Complete API handlers refactoring to eliminate type switching and use repository pattern consistently
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -92,13 +93,7 @@ func CORSPreflightHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Check if origin is allowed
|
||||
originAllowed := false
|
||||
for _, allowed := range allowedOrigins {
|
||||
if origin == allowed {
|
||||
originAllowed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
originAllowed := slices.Contains(allowedOrigins, origin)
|
||||
|
||||
if originAllowed {
|
||||
w.Header().Set("Access-Control-Allow-Origin", origin)
|
||||
|
||||
@@ -1,35 +1,7 @@
|
||||
package api
|
||||
|
||||
import "time"
|
||||
|
||||
// API request/response models
|
||||
type ContentItem struct {
|
||||
ID string `json:"id"`
|
||||
SiteID string `json:"site_id"`
|
||||
HTMLContent string `json:"html_content"`
|
||||
OriginalTemplate string `json:"original_template"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LastEditedBy string `json:"last_edited_by"`
|
||||
}
|
||||
|
||||
type ContentVersion struct {
|
||||
VersionID int64 `json:"version_id"`
|
||||
ContentID string `json:"content_id"`
|
||||
SiteID string `json:"site_id"`
|
||||
HTMLContent string `json:"html_content"`
|
||||
OriginalTemplate string `json:"original_template"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
}
|
||||
|
||||
type ContentResponse struct {
|
||||
Content []ContentItem `json:"content"`
|
||||
}
|
||||
|
||||
type ContentVersionsResponse struct {
|
||||
Versions []ContentVersion `json:"versions"`
|
||||
}
|
||||
// Use db package types directly for API responses - no duplication needed
|
||||
// Request models are kept below as they're different (input DTOs)
|
||||
|
||||
// Element context for backend ID generation
|
||||
type ElementContext struct {
|
||||
@@ -55,44 +27,7 @@ type RollbackContentRequest struct {
|
||||
RolledBackBy string `json:"rolled_back_by,omitempty"`
|
||||
}
|
||||
|
||||
// Collection API models
|
||||
type CollectionItem struct {
|
||||
ID string `json:"id"`
|
||||
SiteID string `json:"site_id"`
|
||||
ContainerHTML string `json:"container_html"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LastEditedBy string `json:"last_edited_by"`
|
||||
Templates []CollectionTemplate `json:"templates,omitempty"`
|
||||
Items []CollectionItemData `json:"items,omitempty"`
|
||||
}
|
||||
|
||||
type CollectionTemplate struct {
|
||||
TemplateID int `json:"template_id"`
|
||||
CollectionID string `json:"collection_id"`
|
||||
SiteID string `json:"site_id"`
|
||||
Name string `json:"name"`
|
||||
HTMLTemplate string `json:"html_template"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
type CollectionItemData struct {
|
||||
ItemID string `json:"item_id"`
|
||||
CollectionID string `json:"collection_id"`
|
||||
SiteID string `json:"site_id"`
|
||||
TemplateID int `json:"template_id"`
|
||||
HTMLContent string `json:"html_content"`
|
||||
Position int `json:"position"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
LastEditedBy string `json:"last_edited_by"`
|
||||
TemplateName string `json:"template_name,omitempty"`
|
||||
}
|
||||
|
||||
type CollectionResponse struct {
|
||||
Collections []CollectionItem `json:"collections"`
|
||||
}
|
||||
// Collection response types also use db package directly
|
||||
|
||||
// Collection request models
|
||||
type CreateCollectionRequest struct {
|
||||
|
||||
@@ -6,6 +6,7 @@ type Config struct {
|
||||
CLI CLIConfig `yaml:"cli" mapstructure:"cli"`
|
||||
Server ServerConfig `yaml:"server" mapstructure:"server"`
|
||||
Auth AuthConfig `yaml:"auth" mapstructure:"auth"`
|
||||
Library LibraryConfig `yaml:"library" mapstructure:"library"`
|
||||
}
|
||||
|
||||
type DatabaseConfig struct {
|
||||
@@ -65,3 +66,11 @@ type DiscoveryConfig struct {
|
||||
Containers bool `yaml:"containers" mapstructure:"containers"`
|
||||
Individual bool `yaml:"individual" mapstructure:"individual"`
|
||||
}
|
||||
|
||||
type LibraryConfig struct {
|
||||
BaseURL string `yaml:"base_url" mapstructure:"base_url"`
|
||||
UseCDN bool `yaml:"use_cdn" mapstructure:"use_cdn"`
|
||||
CDNBaseURL string `yaml:"cdn_base_url" mapstructure:"cdn_base_url"`
|
||||
Minified bool `yaml:"minified" mapstructure:"minified"`
|
||||
Version string `yaml:"version" mapstructure:"version"`
|
||||
}
|
||||
|
||||
@@ -1,956 +0,0 @@
|
||||
/**
|
||||
* INSERTR CSS - Centralized Styles for Content Management Interface
|
||||
*
|
||||
* Architecture: Simple class-based CSS with proper specificity
|
||||
* - Class selectors (0,0,1,0) automatically beat universal selectors (0,0,0,0)
|
||||
* - No cascade layers needed - works in all browsers
|
||||
* - No !important needed - specificity handles conflicts naturally
|
||||
* - Explicit colors prevent inheritance issues
|
||||
*
|
||||
* Components:
|
||||
* - .insertr-gate: Minimal styling for user-defined gates
|
||||
* - .insertr-auth-*: Authentication controls and buttons
|
||||
* - .insertr-form-*: Modal forms and inputs
|
||||
* - .insertr-style-aware-*: Style-aware editor components
|
||||
*/
|
||||
|
||||
/* =================================================================
|
||||
CSS CUSTOM PROPERTIES (CSS VARIABLES)
|
||||
================================================================= */
|
||||
|
||||
:root {
|
||||
/* Core theme colors */
|
||||
--insertr-primary: #007bff;
|
||||
--insertr-primary-hover: #0056b3;
|
||||
--insertr-success: #28a745;
|
||||
--insertr-danger: #dc3545;
|
||||
--insertr-warning: #ffc107;
|
||||
--insertr-info: #17a2b8;
|
||||
|
||||
/* Text colors */
|
||||
--insertr-text-primary: #333333;
|
||||
--insertr-text-secondary: #666666;
|
||||
--insertr-text-muted: #999999;
|
||||
--insertr-text-inverse: #ffffff;
|
||||
|
||||
/* Background colors */
|
||||
--insertr-bg-primary: #ffffff;
|
||||
--insertr-bg-secondary: #f8f9fa;
|
||||
--insertr-bg-overlay: rgba(0, 0, 0, 0.5);
|
||||
|
||||
/* Border and spacing */
|
||||
--insertr-border-color: #dee2e6;
|
||||
--insertr-border-radius: 4px;
|
||||
--insertr-spacing-xs: 4px;
|
||||
--insertr-spacing-sm: 8px;
|
||||
--insertr-spacing-md: 16px;
|
||||
--insertr-spacing-lg: 24px;
|
||||
|
||||
/* Z-index management */
|
||||
--insertr-z-modal-backdrop: 1040;
|
||||
--insertr-z-modal: 1050;
|
||||
--insertr-z-tooltip: 1070;
|
||||
--insertr-z-overlay: 999999;
|
||||
|
||||
/* Typography */
|
||||
--insertr-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||
--insertr-font-size-sm: 12px;
|
||||
--insertr-font-size-base: 14px;
|
||||
--insertr-line-height: 1.4;
|
||||
|
||||
/* Form elements - using existing variables */
|
||||
|
||||
/* Animation */
|
||||
--insertr-transition: all 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
USER-DEFINED GATES
|
||||
Minimal styling - developers control appearance
|
||||
================================================================= */
|
||||
|
||||
.insertr-gate {
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
UNIFIED CONTROL PANEL
|
||||
================================================================= */
|
||||
|
||||
.insertr-control-panel {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
z-index: var(--insertr-z-overlay);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--insertr-spacing-sm);
|
||||
font-family: var(--insertr-font-family);
|
||||
font-size: var(--insertr-font-size-base);
|
||||
max-width: 280px;
|
||||
}
|
||||
|
||||
/* Status Section */
|
||||
.insertr-status-section {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-bottom: var(--insertr-spacing-xs);
|
||||
}
|
||||
|
||||
.insertr-status-indicator {
|
||||
background: var(--insertr-bg-primary);
|
||||
color: var(--insertr-text-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-xs) var(--insertr-spacing-sm);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--insertr-spacing-xs);
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
transition: var(--insertr-transition);
|
||||
}
|
||||
|
||||
.insertr-status-text {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-weight: 500;
|
||||
color: inherit;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.insertr-status-dot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
flex-shrink: 0;
|
||||
transition: var(--insertr-transition);
|
||||
}
|
||||
|
||||
.insertr-status-visitor {
|
||||
background: var(--insertr-text-muted);
|
||||
}
|
||||
|
||||
.insertr-status-authenticated {
|
||||
background: var(--insertr-primary);
|
||||
}
|
||||
|
||||
.insertr-status-editing {
|
||||
background: var(--insertr-success);
|
||||
animation: insertr-pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes insertr-pulse {
|
||||
0%, 100% { opacity: 1; }
|
||||
50% { opacity: 0.6; }
|
||||
}
|
||||
|
||||
/* Action Buttons Section */
|
||||
.insertr-action-section {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--insertr-spacing-xs);
|
||||
}
|
||||
|
||||
.insertr-action-btn {
|
||||
background: var(--insertr-primary);
|
||||
color: var(--insertr-text-inverse);
|
||||
border: none;
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-sm) var(--insertr-spacing-md);
|
||||
margin: 0;
|
||||
font-family: var(--insertr-font-family);
|
||||
font-size: var(--insertr-font-size-base);
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
cursor: pointer;
|
||||
transition: var(--insertr-transition);
|
||||
line-height: var(--insertr-line-height);
|
||||
min-width: 120px;
|
||||
white-space: nowrap;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.insertr-action-btn:hover {
|
||||
background: var(--insertr-primary-hover);
|
||||
color: var(--insertr-text-inverse);
|
||||
text-decoration: none;
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.insertr-action-btn:focus {
|
||||
outline: 2px solid var(--insertr-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.insertr-action-btn:active {
|
||||
transform: translateY(0);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.insertr-action-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
/* Button Type Variants */
|
||||
.insertr-enhance-btn {
|
||||
background: var(--insertr-info);
|
||||
}
|
||||
|
||||
.insertr-enhance-btn:hover {
|
||||
background: #138496;
|
||||
}
|
||||
|
||||
.insertr-edit-btn.insertr-edit-active {
|
||||
background: var(--insertr-success);
|
||||
}
|
||||
|
||||
.insertr-edit-btn.insertr-edit-active:hover {
|
||||
background: #1e7e34;
|
||||
}
|
||||
|
||||
.insertr-auth-btn.insertr-authenticated {
|
||||
background: var(--insertr-text-secondary);
|
||||
}
|
||||
|
||||
.insertr-auth-btn.insertr-authenticated:hover {
|
||||
background: var(--insertr-text-primary);
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
EDITING INDICATORS
|
||||
Visual feedback for editable content
|
||||
================================================================= */
|
||||
|
||||
.insertr-editing-hover {
|
||||
outline: 2px dashed var(--insertr-primary);
|
||||
outline-offset: 2px;
|
||||
background: rgba(0, 123, 255, 0.05);
|
||||
position: relative;
|
||||
transition: var(--insertr-transition);
|
||||
}
|
||||
|
||||
.insertr-editing-hover::after {
|
||||
content: '✏️ Click to edit';
|
||||
position: absolute;
|
||||
top: -30px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: var(--insertr-text-primary);
|
||||
color: var(--insertr-text-inverse);
|
||||
padding: var(--insertr-spacing-xs) var(--insertr-spacing-sm);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
font-family: var(--insertr-font-family);
|
||||
white-space: nowrap;
|
||||
z-index: var(--insertr-z-tooltip);
|
||||
opacity: 0;
|
||||
animation: insertr-tooltip-show 0.2s ease-in-out forwards;
|
||||
}
|
||||
|
||||
@keyframes insertr-tooltip-show {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(-5px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Hide editing indicators when not in edit mode */
|
||||
body:not(.insertr-edit-mode) .insertr-editing-hover {
|
||||
outline: none;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
body:not(.insertr-edit-mode) .insertr-editing-hover::after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
MODAL OVERLAY & CONTAINER
|
||||
================================================================= */
|
||||
|
||||
.insertr-modal-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: var(--insertr-bg-overlay);
|
||||
z-index: var(--insertr-z-modal-backdrop);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: var(--insertr-spacing-lg);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.insertr-modal-container {
|
||||
background: var(--insertr-bg-primary);
|
||||
color: var(--insertr-text-primary);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
max-width: 600px;
|
||||
width: 100%;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
position: relative;
|
||||
z-index: var(--insertr-z-modal);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
STYLE-AWARE EDITOR STYLES
|
||||
Modern interface for content editing with style preservation
|
||||
================================================================= */
|
||||
|
||||
/* Main editor container */
|
||||
.insertr-style-aware-editor {
|
||||
background: var(--insertr-bg-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-lg);
|
||||
min-width: 400px;
|
||||
max-width: 600px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
font-family: var(--insertr-font-family);
|
||||
color: var(--insertr-text-primary);
|
||||
}
|
||||
|
||||
/* Style toolbar */
|
||||
.insertr-style-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--insertr-spacing-xs);
|
||||
padding: var(--insertr-spacing-sm);
|
||||
background: var(--insertr-bg-secondary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
margin-bottom: var(--insertr-spacing-md);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.insertr-toolbar-title {
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
font-weight: 500;
|
||||
color: var(--insertr-text-muted);
|
||||
margin-right: var(--insertr-spacing-xs);
|
||||
}
|
||||
|
||||
.insertr-style-btn {
|
||||
background: var(--insertr-bg-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-xs) var(--insertr-spacing-sm);
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
font-weight: 500;
|
||||
color: var(--insertr-text-primary);
|
||||
cursor: pointer;
|
||||
transition: var(--insertr-transition);
|
||||
}
|
||||
|
||||
.insertr-style-btn:hover {
|
||||
background: var(--insertr-bg-secondary);
|
||||
border-color: var(--insertr-text-muted);
|
||||
}
|
||||
|
||||
.insertr-style-btn:active {
|
||||
background: var(--insertr-border-color);
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
/* Style preview buttons - three-layer architecture for style isolation */
|
||||
.insertr-style-btn.insertr-style-preview {
|
||||
/* Strong button container - prevents content from affecting button structure */
|
||||
background: var(--insertr-bg-primary) !important;
|
||||
border: 1px solid var(--insertr-border-color) !important;
|
||||
border-radius: var(--insertr-border-radius) !important;
|
||||
padding: 6px 10px !important; /* Move padding to button level */
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
cursor: pointer;
|
||||
transition: var(--insertr-transition);
|
||||
|
||||
/* Fixed button dimensions and layout */
|
||||
min-height: 32px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
/* Reset button-level text properties to prevent inheritance */
|
||||
font-family: var(--insertr-font-family);
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
text-transform: none;
|
||||
color: var(--insertr-text-primary);
|
||||
}
|
||||
|
||||
/* Button frame - minimal layout container with no padding */
|
||||
.insertr-button-frame {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
/* Create style containment boundary */
|
||||
contain: layout style;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Style sample - authentic style preview with NO resets */
|
||||
.insertr-style-sample {
|
||||
/* Authentic style preview - let all styling come through naturally */
|
||||
display: inline-block;
|
||||
|
||||
/* Size constraints only */
|
||||
max-width: 100px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
|
||||
/* All other styling (color, weight, transform, decoration, etc.)
|
||||
comes from applied classes - no interference */
|
||||
}
|
||||
|
||||
/* Fallback styling when no meaningful classes are detected */
|
||||
.insertr-style-sample.insertr-fallback-style {
|
||||
color: var(--insertr-text-primary);
|
||||
}
|
||||
|
||||
/* Hover state for preview buttons - subtle visual feedback */
|
||||
.insertr-style-btn.insertr-style-preview:hover {
|
||||
border-color: var(--insertr-text-muted);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Active state for preview buttons */
|
||||
.insertr-style-btn.insertr-style-preview:active {
|
||||
transform: translateY(0);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* Active/applied formatting state - shows current selection has this formatting */
|
||||
.insertr-style-btn.insertr-style-active {
|
||||
background: var(--insertr-primary);
|
||||
border-color: var(--insertr-primary);
|
||||
color: white;
|
||||
box-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
|
||||
}
|
||||
|
||||
.insertr-style-btn.insertr-style-active .insertr-style-sample {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.insertr-style-btn.insertr-style-active:hover {
|
||||
background: var(--insertr-primary-hover);
|
||||
border-color: var(--insertr-primary-hover);
|
||||
transform: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Editor components */
|
||||
.insertr-simple-editor,
|
||||
.insertr-rich-editor,
|
||||
.insertr-fallback-textarea {
|
||||
width: 100%;
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-md);
|
||||
font-size: var(--insertr-font-size-base);
|
||||
line-height: var(--insertr-line-height);
|
||||
font-family: var(--insertr-font-family);
|
||||
color: var(--insertr-text-primary);
|
||||
background: var(--insertr-bg-primary);
|
||||
margin-bottom: var(--insertr-spacing-md);
|
||||
transition: var(--insertr-transition);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.insertr-simple-editor:focus,
|
||||
.insertr-rich-editor:focus,
|
||||
.insertr-fallback-textarea:focus {
|
||||
outline: none;
|
||||
border: 1px solid var(--insertr-primary);
|
||||
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
|
||||
.insertr-simple-editor,
|
||||
.insertr-fallback-textarea {
|
||||
resize: vertical;
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.insertr-rich-editor {
|
||||
min-height: 100px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
MULTI-PROPERTY FORM COMPONENTS
|
||||
Professional form styling for direct editors (links, buttons, images)
|
||||
================================================================= */
|
||||
|
||||
/* Direct editor container */
|
||||
.insertr-direct-editor {
|
||||
background: var(--insertr-bg-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-lg);
|
||||
min-width: 400px;
|
||||
max-width: 600px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
font-family: var(--insertr-font-family);
|
||||
color: var(--insertr-text-primary);
|
||||
}
|
||||
|
||||
/* Form groups */
|
||||
.insertr-form-group {
|
||||
margin-bottom: var(--insertr-spacing-md);
|
||||
}
|
||||
|
||||
.insertr-form-group:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* Form labels */
|
||||
.insertr-form-label {
|
||||
display: block;
|
||||
margin-bottom: var(--insertr-spacing-xs);
|
||||
font-weight: 500;
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
color: var(--insertr-text-primary);
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
/* Form inputs and selects */
|
||||
.insertr-form-input,
|
||||
.insertr-form-select {
|
||||
width: 100%;
|
||||
padding: var(--insertr-spacing-sm) var(--insertr-spacing-md);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
font-size: var(--insertr-font-size-base);
|
||||
font-family: var(--insertr-font-family);
|
||||
line-height: 1.4;
|
||||
color: var(--insertr-text-primary);
|
||||
background: var(--insertr-bg-primary);
|
||||
transition: var(--insertr-transition);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* Focus states */
|
||||
.insertr-form-input:focus,
|
||||
.insertr-form-select:focus {
|
||||
outline: none;
|
||||
border-color: var(--insertr-primary);
|
||||
box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
|
||||
/* Hover states for selects */
|
||||
.insertr-form-select:hover {
|
||||
border-color: var(--insertr-text-secondary);
|
||||
}
|
||||
|
||||
/* Disabled states */
|
||||
.insertr-form-input:disabled,
|
||||
.insertr-form-select:disabled {
|
||||
background: var(--insertr-bg-secondary);
|
||||
color: var(--insertr-text-muted);
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
/* Error states */
|
||||
.insertr-form-input.insertr-error,
|
||||
.insertr-form-select.insertr-error {
|
||||
border-color: var(--insertr-danger);
|
||||
box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.25);
|
||||
}
|
||||
|
||||
/* Success states */
|
||||
.insertr-form-input.insertr-success,
|
||||
.insertr-form-select.insertr-success {
|
||||
border-color: var(--insertr-success);
|
||||
box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.25);
|
||||
}
|
||||
|
||||
/* Form validation messages */
|
||||
.insertr-form-message {
|
||||
margin-top: var(--insertr-spacing-xs);
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.insertr-form-message.insertr-error {
|
||||
color: var(--insertr-danger);
|
||||
}
|
||||
|
||||
.insertr-form-message.insertr-success {
|
||||
color: var(--insertr-success);
|
||||
}
|
||||
|
||||
.insertr-form-message.insertr-info {
|
||||
color: var(--insertr-info);
|
||||
}
|
||||
|
||||
/* Specific editor variants */
|
||||
.insertr-link-editor {
|
||||
/* Link-specific styling if needed */
|
||||
}
|
||||
|
||||
.insertr-button-editor {
|
||||
/* Button-specific styling if needed */
|
||||
}
|
||||
|
||||
.insertr-image-editor {
|
||||
/* Image-specific styling if needed */
|
||||
}
|
||||
|
||||
/* Form actions */
|
||||
.insertr-form-actions {
|
||||
display: flex;
|
||||
gap: var(--insertr-spacing-sm);
|
||||
justify-content: flex-end;
|
||||
margin: 0;
|
||||
padding: var(--insertr-spacing-md) 0 0 0;
|
||||
border-top: 1px solid var(--insertr-border-color);
|
||||
}
|
||||
|
||||
.insertr-btn-save,
|
||||
.insertr-btn-cancel,
|
||||
.insertr-btn-history {
|
||||
background: var(--insertr-primary);
|
||||
color: var(--insertr-text-inverse);
|
||||
border: none;
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-sm) var(--insertr-spacing-md);
|
||||
margin: 0;
|
||||
font-family: var(--insertr-font-family);
|
||||
font-size: var(--insertr-font-size-base);
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: var(--insertr-transition);
|
||||
line-height: var(--insertr-line-height);
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.insertr-btn-cancel {
|
||||
background: var(--insertr-text-secondary);
|
||||
color: var(--insertr-text-inverse);
|
||||
}
|
||||
|
||||
.insertr-btn-cancel:hover {
|
||||
background: var(--insertr-text-primary);
|
||||
color: var(--insertr-text-inverse);
|
||||
}
|
||||
|
||||
.insertr-btn-history {
|
||||
background: var(--insertr-info);
|
||||
color: var(--insertr-text-inverse);
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.insertr-btn-history:hover {
|
||||
background: #138496;
|
||||
color: var(--insertr-text-inverse);
|
||||
}
|
||||
|
||||
.insertr-btn-save:hover {
|
||||
background: var(--insertr-primary-hover);
|
||||
color: var(--insertr-text-inverse);
|
||||
}
|
||||
|
||||
.insertr-btn-save:focus,
|
||||
.insertr-btn-cancel:focus,
|
||||
.insertr-btn-history:focus {
|
||||
outline: 2px solid var(--insertr-primary);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
/* Fallback editor */
|
||||
.insertr-fallback-editor {
|
||||
background: var(--insertr-bg-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-lg);
|
||||
min-width: 400px;
|
||||
max-width: 500px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
font-family: var(--insertr-font-family);
|
||||
color: var(--insertr-text-primary);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* =================================================================
|
||||
STATUS AND FEEDBACK MESSAGES
|
||||
================================================================= */
|
||||
|
||||
.insertr-status-message {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
z-index: var(--insertr-z-overlay);
|
||||
background: var(--insertr-bg-primary);
|
||||
color: var(--insertr-text-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
padding: var(--insertr-spacing-md);
|
||||
margin: 0;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
font-family: var(--insertr-font-family);
|
||||
font-size: var(--insertr-font-size-base);
|
||||
line-height: var(--insertr-line-height);
|
||||
max-width: 300px;
|
||||
transition: var(--insertr-transition);
|
||||
}
|
||||
|
||||
.insertr-status-message.success {
|
||||
border-color: var(--insertr-success);
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
|
||||
.insertr-status-message.error {
|
||||
border-color: var(--insertr-danger);
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
|
||||
.insertr-status-message.warning {
|
||||
border-color: var(--insertr-warning);
|
||||
background: #fff3cd;
|
||||
color: #856404;
|
||||
}
|
||||
|
||||
.insertr-status-text {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-weight: 500;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
UTILITY CLASSES
|
||||
================================================================= */
|
||||
|
||||
.insertr-hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.insertr-sr-only {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
padding: 0;
|
||||
margin: -1px;
|
||||
overflow: hidden;
|
||||
clip: rect(0, 0, 0, 0);
|
||||
white-space: nowrap;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
RESPONSIVE DESIGN
|
||||
================================================================= */
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.insertr-modal-overlay {
|
||||
padding: var(--insertr-spacing-sm);
|
||||
}
|
||||
|
||||
.insertr-control-panel {
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
max-width: 240px;
|
||||
}
|
||||
|
||||
.insertr-action-btn {
|
||||
min-width: 100px;
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
padding: var(--insertr-spacing-xs) var(--insertr-spacing-sm);
|
||||
}
|
||||
|
||||
.insertr-status-indicator {
|
||||
font-size: 11px;
|
||||
padding: 3px var(--insertr-spacing-xs);
|
||||
}
|
||||
|
||||
.insertr-editing-hover::after {
|
||||
font-size: 11px;
|
||||
padding: 2px var(--insertr-spacing-xs);
|
||||
top: -25px;
|
||||
}
|
||||
|
||||
/* StyleAware Editor responsive adjustments */
|
||||
.insertr-style-aware-editor,
|
||||
.insertr-fallback-editor {
|
||||
min-width: 300px;
|
||||
max-width: calc(100vw - 2rem);
|
||||
padding: var(--insertr-spacing-md);
|
||||
}
|
||||
|
||||
.insertr-style-toolbar {
|
||||
padding: var(--insertr-spacing-xs);
|
||||
gap: var(--insertr-spacing-xs);
|
||||
}
|
||||
|
||||
.insertr-style-btn {
|
||||
padding: var(--insertr-spacing-xs);
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
}
|
||||
|
||||
.insertr-form-actions {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.insertr-btn-save,
|
||||
.insertr-btn-cancel {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.insertr-btn-history {
|
||||
margin-right: 0;
|
||||
order: -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
COLLECTION MANAGEMENT STYLES (.insertr-add)
|
||||
================================================================= */
|
||||
|
||||
/* Collection container when active */
|
||||
.insertr-collection-active {
|
||||
outline: 2px dashed var(--insertr-primary);
|
||||
outline-offset: 4px;
|
||||
border-radius: var(--insertr-border-radius);
|
||||
}
|
||||
|
||||
/* Add button positioned in top right of container */
|
||||
.insertr-add-btn {
|
||||
position: absolute;
|
||||
top: -12px;
|
||||
right: -12px;
|
||||
background: var(--insertr-primary);
|
||||
color: var(--insertr-text-inverse);
|
||||
border: none;
|
||||
padding: var(--insertr-spacing-xs) var(--insertr-spacing-sm);
|
||||
border-radius: var(--insertr-border-radius);
|
||||
font-size: var(--insertr-font-size-sm);
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
z-index: var(--insertr-z-floating);
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.insertr-add-btn:hover {
|
||||
background: var(--insertr-primary-hover);
|
||||
transform: translateY(-1px);
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
.insertr-add-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* Item controls positioned in top right corner of each item */
|
||||
.insertr-item-controls {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
display: flex;
|
||||
gap: 2px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
z-index: var(--insertr-z-floating);
|
||||
}
|
||||
|
||||
/* Individual control buttons */
|
||||
.insertr-control-btn {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
background: var(--insertr-bg-primary);
|
||||
border: 1px solid var(--insertr-border-color);
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--insertr-text-primary);
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.insertr-control-btn:hover {
|
||||
background: var(--insertr-bg-secondary);
|
||||
border-color: var(--insertr-primary);
|
||||
color: var(--insertr-primary);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
/* Remove button specific styling */
|
||||
.insertr-control-btn:last-child {
|
||||
color: var(--insertr-danger);
|
||||
}
|
||||
|
||||
.insertr-control-btn:last-child:hover {
|
||||
background: var(--insertr-danger);
|
||||
color: var(--insertr-text-inverse);
|
||||
border-color: var(--insertr-danger);
|
||||
}
|
||||
|
||||
/* Collection items hover state */
|
||||
.insertr-collection-active > *:hover {
|
||||
background: rgba(0, 123, 255, 0.03);
|
||||
outline: 1px solid rgba(var(--insertr-primary), 0.2);
|
||||
outline-offset: 2px;
|
||||
border-radius: var(--insertr-border-radius);
|
||||
}
|
||||
|
||||
/* Show item controls on hover */
|
||||
.insertr-collection-active > *:hover .insertr-item-controls {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
/* Responsive adjustments for collection management */
|
||||
@media (max-width: 768px) {
|
||||
.insertr-add-btn {
|
||||
position: static;
|
||||
display: block;
|
||||
margin: var(--insertr-spacing-sm) auto 0;
|
||||
width: 100%;
|
||||
max-width: 200px;
|
||||
}
|
||||
|
||||
.insertr-item-controls {
|
||||
position: relative;
|
||||
opacity: 1;
|
||||
top: auto;
|
||||
right: auto;
|
||||
justify-content: center;
|
||||
margin-top: var(--insertr-spacing-xs);
|
||||
}
|
||||
|
||||
.insertr-control-btn {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Embedded library assets
|
||||
//
|
||||
//go:embed assets/insertr.min.js
|
||||
var libraryMinJS string
|
||||
|
||||
//go:embed assets/insertr.js
|
||||
var libraryJS string
|
||||
|
||||
// GetLibraryScript returns the appropriate library version
|
||||
func GetLibraryScript(minified bool) string {
|
||||
if minified {
|
||||
return libraryMinJS
|
||||
}
|
||||
return libraryJS
|
||||
}
|
||||
|
||||
// GetLibraryVersion returns the current embedded library version
|
||||
func GetLibraryVersion() string {
|
||||
return "1.0.0"
|
||||
}
|
||||
|
||||
// GetLibraryURL returns the appropriate library URL for script injection
|
||||
func GetLibraryURL(minified bool, isDevelopment bool) string {
|
||||
if isDevelopment {
|
||||
// Local development URLs - relative to served content
|
||||
if minified {
|
||||
return "/insertr/insertr.min.js"
|
||||
}
|
||||
return "/insertr/insertr.js"
|
||||
}
|
||||
|
||||
// Production URLs - use CDN
|
||||
return GetLibraryCDNURL(minified)
|
||||
}
|
||||
|
||||
// GetLibraryCDNURL returns the CDN URL for production use
|
||||
func GetLibraryCDNURL(minified bool) string {
|
||||
version := GetLibraryVersion()
|
||||
if minified {
|
||||
return fmt.Sprintf("https://cdn.jsdelivr.net/npm/@insertr/lib@%s/dist/insertr.min.js", version)
|
||||
}
|
||||
return fmt.Sprintf("https://cdn.jsdelivr.net/npm/@insertr/lib@%s/dist/insertr.js", version)
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
package content
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
)
|
||||
|
||||
// MockClient implements ContentClient with mock data for development
|
||||
type MockClient struct {
|
||||
data map[string]db.ContentItem
|
||||
}
|
||||
|
||||
// NewMockClient creates a new mock content client with sample data
|
||||
func NewMockClient() *MockClient {
|
||||
// Generate realistic mock content based on actual generated IDs
|
||||
data := map[string]db.ContentItem{
|
||||
// Navigation (index.html has collision suffix)
|
||||
"navbar-logo-2b10ad": {
|
||||
ID: "navbar-logo-2b10ad",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "Acme Consulting Solutions",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
"navbar-logo-2b10ad-a44bad": {
|
||||
ID: "navbar-logo-2b10ad-a44bad",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "Acme Business Advisors",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
|
||||
// Hero Section - index.html (updated with actual IDs)
|
||||
"hero-title-7cfeea": {
|
||||
ID: "hero-title-7cfeea",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "Transform Your Business with Strategic Expertise",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
"hero-lead-e47475": {
|
||||
ID: "hero-lead-e47475",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "We help <strong>ambitious businesses</strong> grow through strategic planning, process optimization, and digital transformation. Our team brings 20+ years of experience to accelerate your success.",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
"hero-link-76c620": {
|
||||
ID: "hero-link-76c620",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "Schedule Free Consultation",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
|
||||
// Hero Section - about.html
|
||||
"hero-title-c70343": {
|
||||
ID: "hero-title-c70343",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "About Our Consulting Expertise",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
"hero-lead-673026": {
|
||||
ID: "hero-lead-673026",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "We're a team of <strong>experienced consultants</strong> dedicated to helping small businesses thrive in today's competitive marketplace through proven strategies.",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
|
||||
// Services Section
|
||||
"services-subtitle-c8927c": {
|
||||
ID: "services-subtitle-c8927c",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "Our Story",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
"services-text-0d96da": {
|
||||
ID: "services-text-0d96da",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "<strong>Founded in 2020</strong>, Acme Consulting emerged from a simple observation: small businesses needed access to the same high-quality strategic advice that large corporations receive, but in a format that was accessible, affordable, and actionable.",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
|
||||
// Default fallback for any missing content
|
||||
"default": {
|
||||
ID: "default",
|
||||
SiteID: "demo",
|
||||
HTMLContent: "[Enhanced Content]",
|
||||
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
},
|
||||
}
|
||||
|
||||
return &MockClient{data: data}
|
||||
}
|
||||
|
||||
// GetContent fetches a single content item by ID
|
||||
func (m *MockClient) GetContent(ctx context.Context, siteID, contentID string) (*db.ContentItem, error) {
|
||||
if item, exists := m.data[contentID]; exists && item.SiteID == siteID {
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// Return nil for missing content - this will preserve original HTML content
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// GetBulkContent fetches multiple content items by IDs
|
||||
func (m *MockClient) GetBulkContent(ctx context.Context, siteID string, contentIDs []string) (map[string]db.ContentItem, error) {
|
||||
result := make(map[string]db.ContentItem)
|
||||
|
||||
for _, id := range contentIDs {
|
||||
item, err := m.GetContent(ctx, siteID, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if item != nil {
|
||||
result[id] = *item
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetAllContent fetches all content for a site
|
||||
func (m *MockClient) GetAllContent(ctx context.Context, siteID string) (map[string]db.ContentItem, error) {
|
||||
result := make(map[string]db.ContentItem)
|
||||
|
||||
for _, item := range m.data {
|
||||
if item.SiteID == siteID {
|
||||
result[item.ID] = item
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// CreateContent creates a new mock content item
|
||||
func (m *MockClient) CreateContent(ctx context.Context, siteID, contentID, htmlContent, originalTemplate, lastEditedBy string) (*db.ContentItem, error) {
|
||||
// For mock client, just create and store the item
|
||||
item := db.ContentItem{
|
||||
ID: contentID,
|
||||
SiteID: siteID,
|
||||
HTMLContent: htmlContent,
|
||||
OriginalTemplate: originalTemplate,
|
||||
UpdatedAt: time.Now().Format(time.RFC3339),
|
||||
LastEditedBy: lastEditedBy,
|
||||
}
|
||||
|
||||
// Store in mock data
|
||||
m.data[contentID] = item
|
||||
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// Collection method stubs - TODO: Implement these for mock testing
|
||||
func (m *MockClient) GetCollection(ctx context.Context, siteID, collectionID string) (*db.CollectionItem, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
func (m *MockClient) CreateCollection(ctx context.Context, siteID, collectionID, containerHTML, lastEditedBy string) (*db.CollectionItem, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
func (m *MockClient) GetCollectionItems(ctx context.Context, siteID, collectionID string) ([]db.CollectionItemWithTemplate, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
func (m *MockClient) CreateCollectionTemplate(ctx context.Context, siteID, collectionID, name, htmlTemplate string, isDefault bool) (*db.CollectionTemplateItem, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
func (m *MockClient) GetCollectionTemplates(ctx context.Context, siteID, collectionID string) ([]db.CollectionTemplateItem, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
func (m *MockClient) CreateCollectionItem(ctx context.Context, siteID, collectionID, itemID string, templateID int, htmlContent string, position int, lastEditedBy string) (*db.CollectionItemWithTemplate, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
func (m *MockClient) CreateCollectionItemAtomic(ctx context.Context, siteID, collectionID string, templateID int, lastEditedBy string) (*db.CollectionItemWithTemplate, error) {
|
||||
return nil, fmt.Errorf("collection operations not implemented in MockClient")
|
||||
}
|
||||
|
||||
// WithTransaction executes a function within a transaction (not supported for mock client)
|
||||
func (m *MockClient) WithTransaction(ctx context.Context, fn func(db.ContentRepository) error) error {
|
||||
return fmt.Errorf("transactions not supported for mock client")
|
||||
}
|
||||
@@ -11,14 +11,12 @@ import (
|
||||
"github.com/insertr/insertr/internal/config"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"github.com/insertr/insertr/internal/engine"
|
||||
"maps"
|
||||
)
|
||||
|
||||
// Type alias for backward compatibility
|
||||
type SiteConfig = config.SiteConfig
|
||||
|
||||
// SiteManager handles registration and enhancement of static sites
|
||||
type SiteManager struct {
|
||||
sites map[string]*SiteConfig
|
||||
sites map[string]*config.SiteConfig
|
||||
enhancer *Enhancer
|
||||
mutex sync.RWMutex
|
||||
devMode bool
|
||||
@@ -29,7 +27,7 @@ type SiteManager struct {
|
||||
// NewSiteManager creates a new site manager
|
||||
func NewSiteManager(contentClient db.ContentRepository, devMode bool) *SiteManager {
|
||||
return &SiteManager{
|
||||
sites: make(map[string]*SiteConfig),
|
||||
sites: make(map[string]*config.SiteConfig),
|
||||
enhancer: NewDefaultEnhancer(contentClient, ""), // siteID will be set per operation
|
||||
devMode: devMode,
|
||||
contentClient: contentClient,
|
||||
@@ -43,7 +41,7 @@ func NewSiteManagerWithAuth(contentClient db.ContentRepository, devMode bool, au
|
||||
authProvider = &engine.AuthProvider{Type: "mock"}
|
||||
}
|
||||
return &SiteManager{
|
||||
sites: make(map[string]*SiteConfig),
|
||||
sites: make(map[string]*config.SiteConfig),
|
||||
contentClient: contentClient,
|
||||
authProvider: authProvider,
|
||||
devMode: devMode,
|
||||
@@ -51,7 +49,7 @@ func NewSiteManagerWithAuth(contentClient db.ContentRepository, devMode bool, au
|
||||
}
|
||||
|
||||
// RegisterSite adds a site to the manager
|
||||
func (sm *SiteManager) RegisterSite(config *SiteConfig) error {
|
||||
func (sm *SiteManager) RegisterSite(config *config.SiteConfig) error {
|
||||
sm.mutex.Lock()
|
||||
defer sm.mutex.Unlock()
|
||||
|
||||
@@ -90,7 +88,7 @@ func (sm *SiteManager) RegisterSite(config *SiteConfig) error {
|
||||
}
|
||||
|
||||
// RegisterSites bulk registers multiple sites from configuration
|
||||
func (sm *SiteManager) RegisterSites(configs []*SiteConfig) error {
|
||||
func (sm *SiteManager) RegisterSites(configs []*config.SiteConfig) error {
|
||||
for _, config := range configs {
|
||||
if err := sm.RegisterSite(config); err != nil {
|
||||
return fmt.Errorf("failed to register site %s: %w", config.SiteID, err)
|
||||
@@ -100,7 +98,7 @@ func (sm *SiteManager) RegisterSites(configs []*SiteConfig) error {
|
||||
}
|
||||
|
||||
// GetSite returns a registered site configuration
|
||||
func (sm *SiteManager) GetSite(siteID string) (*SiteConfig, bool) {
|
||||
func (sm *SiteManager) GetSite(siteID string) (*config.SiteConfig, bool) {
|
||||
sm.mutex.RLock()
|
||||
defer sm.mutex.RUnlock()
|
||||
|
||||
@@ -109,15 +107,13 @@ func (sm *SiteManager) GetSite(siteID string) (*SiteConfig, bool) {
|
||||
}
|
||||
|
||||
// GetAllSites returns all registered sites
|
||||
func (sm *SiteManager) GetAllSites() map[string]*SiteConfig {
|
||||
func (sm *SiteManager) GetAllSites() map[string]*config.SiteConfig {
|
||||
sm.mutex.RLock()
|
||||
defer sm.mutex.RUnlock()
|
||||
|
||||
// Return a copy to prevent external modification
|
||||
result := make(map[string]*SiteConfig)
|
||||
for id, site := range sm.sites {
|
||||
result[id] = site
|
||||
}
|
||||
result := make(map[string]*config.SiteConfig)
|
||||
maps.Copy(result, sm.sites)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -189,7 +185,7 @@ func (sm *SiteManager) EnhanceSite(siteID string) error {
|
||||
// EnhanceAllSites enhances all registered sites that have auto-enhancement enabled
|
||||
func (sm *SiteManager) EnhanceAllSites() error {
|
||||
sm.mutex.RLock()
|
||||
sites := make([]*SiteConfig, 0, len(sm.sites))
|
||||
sites := make([]*config.SiteConfig, 0, len(sm.sites))
|
||||
for _, site := range sm.sites {
|
||||
if site.AutoEnhance {
|
||||
sites = append(sites, site)
|
||||
@@ -212,7 +208,7 @@ func (sm *SiteManager) EnhanceAllSites() error {
|
||||
}
|
||||
|
||||
// GetStats returns statistics about registered sites
|
||||
func (sm *SiteManager) GetStats() map[string]interface{} {
|
||||
func (sm *SiteManager) GetStats() map[string]any {
|
||||
sm.mutex.RLock()
|
||||
defer sm.mutex.RUnlock()
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
)
|
||||
|
||||
// ContentRepository interface for accessing content data
|
||||
// This replaces the ContentClient interface from engine package
|
||||
type ContentRepository interface {
|
||||
GetContent(ctx context.Context, siteID, contentID string) (*ContentItem, error)
|
||||
GetBulkContent(ctx context.Context, siteID string, contentIDs []string) (map[string]ContentItem, error)
|
||||
|
||||
@@ -29,7 +29,7 @@ func NewContentEngine(client db.ContentRepository) *ContentEngine {
|
||||
idGenerator: NewIDGenerator(),
|
||||
client: client,
|
||||
authProvider: authProvider,
|
||||
injector: NewInjector(client, ""), // siteID will be set per operation
|
||||
injector: NewInjector(client, "", nil), // siteID will be set per operation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func NewContentEngineWithAuth(client db.ContentRepository, authProvider *AuthPro
|
||||
idGenerator: NewIDGenerator(),
|
||||
client: client,
|
||||
authProvider: authProvider,
|
||||
injector: NewInjectorWithAuth(client, "", authProvider), // siteID will be set per operation
|
||||
injector: NewInjectorWithAuth(client, "", authProvider, nil), // siteID will be set per operation
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (e *ContentEngine) ProcessContent(input ContentInput) (*ContentResult, erro
|
||||
|
||||
// 6. Inject editor assets for enhancement mode (development)
|
||||
if input.Mode == Enhancement {
|
||||
injector := NewInjectorWithAuth(e.client, input.SiteID, e.authProvider)
|
||||
injector := NewInjectorWithAuth(e.client, input.SiteID, e.authProvider, nil)
|
||||
injector.InjectEditorAssets(doc, true, "")
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ func (e *ContentEngine) reconstructCollectionItems(collectionNode *html.Node, co
|
||||
|
||||
if structuralBody != nil {
|
||||
// Process each .insertr element using Injector pattern (unified approach)
|
||||
injector := NewInjector(e.client, siteID)
|
||||
injector := NewInjector(e.client, siteID, nil)
|
||||
|
||||
// Walk through structural elements and hydrate with content from content table
|
||||
e.walkNodes(structuralBody, func(n *html.Node) {
|
||||
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/insertr/insertr/internal/config"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"golang.org/x/net/html"
|
||||
"slices"
|
||||
)
|
||||
|
||||
// Injector handles content injection into HTML elements
|
||||
@@ -15,19 +17,21 @@ type Injector struct {
|
||||
client db.ContentRepository
|
||||
siteID string
|
||||
authProvider *AuthProvider
|
||||
config *config.Config
|
||||
}
|
||||
|
||||
// NewInjector creates a new content injector
|
||||
func NewInjector(client db.ContentRepository, siteID string) *Injector {
|
||||
func NewInjector(client db.ContentRepository, siteID string, cfg *config.Config) *Injector {
|
||||
return &Injector{
|
||||
client: client,
|
||||
siteID: siteID,
|
||||
authProvider: &AuthProvider{Type: "mock"}, // default
|
||||
config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
// NewInjectorWithAuth creates a new content injector with auth provider
|
||||
func NewInjectorWithAuth(client db.ContentRepository, siteID string, authProvider *AuthProvider) *Injector {
|
||||
func NewInjectorWithAuth(client db.ContentRepository, siteID string, authProvider *AuthProvider, cfg *config.Config) *Injector {
|
||||
if authProvider == nil {
|
||||
authProvider = &AuthProvider{Type: "mock"}
|
||||
}
|
||||
@@ -35,6 +39,7 @@ func NewInjectorWithAuth(client db.ContentRepository, siteID string, authProvide
|
||||
client: client,
|
||||
siteID: siteID,
|
||||
authProvider: authProvider,
|
||||
config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +205,7 @@ func (i *Injector) setAttribute(node *html.Node, key, value string) {
|
||||
// Remove existing attribute if present
|
||||
for idx, attr := range node.Attr {
|
||||
if attr.Key == key {
|
||||
node.Attr = append(node.Attr[:idx], node.Attr[idx+1:]...)
|
||||
node.Attr = slices.Delete(node.Attr, idx, idx+1)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -232,10 +237,8 @@ func (i *Injector) addClass(node *html.Node, className string) {
|
||||
}
|
||||
|
||||
// Check if class already exists
|
||||
for _, class := range classes {
|
||||
if class == className {
|
||||
return // Class already exists
|
||||
}
|
||||
if slices.Contains(classes, className) {
|
||||
return // Class already exists
|
||||
}
|
||||
|
||||
// Add new class
|
||||
@@ -327,8 +330,15 @@ func (i *Injector) InjectEditorScript(doc *html.Node) {
|
||||
if i.authProvider != nil {
|
||||
authProvider = i.authProvider.Type
|
||||
}
|
||||
insertrHTML := fmt.Sprintf(`<link rel="stylesheet" href="http://localhost:8080/insertr.css" data-insertr-injected="true">
|
||||
<script src="http://localhost:8080/insertr.js" data-insertr-injected="true" data-site-id="%s" data-api-endpoint="http://localhost:8080/api/content" data-auth-provider="%s" data-debug="true"></script>`, i.siteID, authProvider)
|
||||
|
||||
// Generate configurable URLs for library assets
|
||||
cssURL := i.getLibraryURL("insertr.css")
|
||||
jsURL := i.getLibraryURL("insertr.js")
|
||||
apiURL := i.getAPIURL()
|
||||
|
||||
insertrHTML := fmt.Sprintf(`<link rel="stylesheet" href="%s" data-insertr-injected="true">
|
||||
<script src="%s" data-insertr-injected="true" data-site-id="%s" data-api-endpoint="%s" data-auth-provider="%s" data-debug="%t"></script>`,
|
||||
cssURL, jsURL, i.siteID, apiURL, authProvider, i.isDebugMode())
|
||||
|
||||
// Parse and inject the CSS and script elements
|
||||
insertrDoc, err := html.Parse(strings.NewReader(insertrHTML))
|
||||
@@ -346,38 +356,6 @@ func (i *Injector) InjectEditorScript(doc *html.Node) {
|
||||
log.Printf("✅ Insertr.js library injected with site configuration")
|
||||
}
|
||||
|
||||
// injectAllScriptElements finds and injects all script elements from parsed HTML
|
||||
func (i *Injector) injectAllScriptElements(doc *html.Node, targetNode *html.Node) error {
|
||||
scripts := i.findAllScriptElements(doc)
|
||||
|
||||
for _, script := range scripts {
|
||||
// Remove from original parent
|
||||
if script.Parent != nil {
|
||||
script.Parent.RemoveChild(script)
|
||||
}
|
||||
// Add to target node
|
||||
targetNode.AppendChild(script)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// findAllScriptElements recursively finds all script elements
|
||||
func (i *Injector) findAllScriptElements(node *html.Node) []*html.Node {
|
||||
var scripts []*html.Node
|
||||
|
||||
if node.Type == html.ElementNode && node.Data == "script" {
|
||||
scripts = append(scripts, node)
|
||||
}
|
||||
|
||||
for child := node.FirstChild; child != nil; child = child.NextSibling {
|
||||
childScripts := i.findAllScriptElements(child)
|
||||
scripts = append(scripts, childScripts...)
|
||||
}
|
||||
|
||||
return scripts
|
||||
}
|
||||
|
||||
// injectAllHeadElements finds and injects all head elements (link, script) from parsed HTML
|
||||
func (i *Injector) injectAllHeadElements(doc *html.Node, targetNode *html.Node) error {
|
||||
elements := i.findAllHeadElements(doc)
|
||||
@@ -479,15 +457,69 @@ func (i *Injector) extractElementByClass(node *html.Node, className string) *htm
|
||||
return nil
|
||||
}
|
||||
|
||||
// extractElementByTag finds element with specific tag
|
||||
func (i *Injector) extractElementByTag(node *html.Node, tagName string) *html.Node {
|
||||
if node.Type == html.ElementNode && node.Data == tagName {
|
||||
return node
|
||||
// getLibraryURL returns the appropriate URL for library assets (CSS/JS)
|
||||
func (i *Injector) getLibraryURL(filename string) string {
|
||||
if i.config == nil {
|
||||
// Fallback to localhost if no config
|
||||
return fmt.Sprintf("http://localhost:8080/%s", filename)
|
||||
}
|
||||
for child := node.FirstChild; child != nil; child = child.NextSibling {
|
||||
if result := i.extractElementByTag(child, tagName); result != nil {
|
||||
return result
|
||||
|
||||
// Check if we should use CDN
|
||||
if i.config.Library.UseCDN && i.config.Library.CDNBaseURL != "" {
|
||||
// Production: Use CDN
|
||||
suffix := ""
|
||||
if i.config.Library.Minified && filename == "insertr.js" {
|
||||
suffix = ".min"
|
||||
}
|
||||
baseName := strings.TrimSuffix(filename, ".js")
|
||||
baseName = strings.TrimSuffix(baseName, ".css")
|
||||
return fmt.Sprintf("%s@%s/dist/%s%s", i.config.Library.CDNBaseURL, i.config.Library.Version, baseName, suffix+getFileExtension(filename))
|
||||
}
|
||||
return nil
|
||||
|
||||
// Development: Use local server
|
||||
baseURL := i.config.Library.BaseURL
|
||||
if baseURL == "" {
|
||||
baseURL = fmt.Sprintf("http://localhost:%d", i.config.Server.Port)
|
||||
}
|
||||
|
||||
suffix := ""
|
||||
if i.config.Library.Minified && filename == "insertr.js" {
|
||||
suffix = ".min"
|
||||
}
|
||||
baseName := strings.TrimSuffix(filename, ".js")
|
||||
baseName = strings.TrimSuffix(baseName, ".css")
|
||||
return fmt.Sprintf("%s/%s%s", baseURL, baseName, suffix+getFileExtension(filename))
|
||||
}
|
||||
|
||||
// getAPIURL returns the API endpoint URL
|
||||
func (i *Injector) getAPIURL() string {
|
||||
if i.config == nil {
|
||||
return "http://localhost:8080/api/content"
|
||||
}
|
||||
|
||||
baseURL := i.config.Library.BaseURL
|
||||
if baseURL == "" {
|
||||
baseURL = fmt.Sprintf("http://localhost:%d", i.config.Server.Port)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s/api/content", baseURL)
|
||||
}
|
||||
|
||||
// isDebugMode returns true if in development mode
|
||||
func (i *Injector) isDebugMode() bool {
|
||||
if i.config == nil {
|
||||
return true
|
||||
}
|
||||
return i.config.Auth.DevMode
|
||||
}
|
||||
|
||||
// getFileExtension returns the file extension including the dot
|
||||
func getFileExtension(filename string) string {
|
||||
if strings.HasSuffix(filename, ".js") {
|
||||
return ".js"
|
||||
}
|
||||
if strings.HasSuffix(filename, ".css") {
|
||||
return ".css"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user