Complete API handlers refactoring to eliminate type switching and use repository pattern consistently
This commit is contained in:
20
CHECKLIST.md
Normal file
20
CHECKLIST.md
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Before v0.1
|
||||||
|
- [x] .insertr-gate
|
||||||
|
- [x] .insertr
|
||||||
|
- [ ] .insertr-content / .insertr-article
|
||||||
|
- [x] .insertr-add
|
||||||
|
- [ ] .insertr history and version control. Users can see previous version and see who changed what.
|
||||||
|
- [ ] Authentication
|
||||||
|
- [ ] Set up Authentik app
|
||||||
|
- [ ] Dev dashboard
|
||||||
|
- [ ] Overview of your sites
|
||||||
|
- [ ] Manage editor access
|
||||||
|
- [ ] User dashboard?
|
||||||
|
|
||||||
|
- [ ] Production checklist
|
||||||
|
- [ ] Library served from CDN
|
||||||
|
- [ ] Clean up app configuration
|
||||||
|
- [ ] Complete documentation.
|
||||||
|
|
||||||
|
# Sometime
|
||||||
|
- [ ] Product/library website
|
||||||
@@ -105,8 +105,7 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
|||||||
defer database.Close()
|
defer database.Close()
|
||||||
client = database.NewContentRepository()
|
client = database.NewContentRepository()
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("🧪 No database or API configured, using mock content\n")
|
panic("🧪 No database or API configured\n")
|
||||||
client = content.NewMockClient()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load site-specific configuration
|
// Load site-specific configuration
|
||||||
|
|||||||
36
cmd/serve.go
36
cmd/serve.go
@@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/insertr/insertr/internal/api"
|
"github.com/insertr/insertr/internal/api"
|
||||||
"github.com/insertr/insertr/internal/auth"
|
"github.com/insertr/insertr/internal/auth"
|
||||||
|
"github.com/insertr/insertr/internal/config"
|
||||||
"github.com/insertr/insertr/internal/content"
|
"github.com/insertr/insertr/internal/content"
|
||||||
"github.com/insertr/insertr/internal/db"
|
"github.com/insertr/insertr/internal/db"
|
||||||
"github.com/insertr/insertr/internal/engine"
|
"github.com/insertr/insertr/internal/engine"
|
||||||
@@ -109,9 +110,9 @@ func runServe(cmd *cobra.Command, args []string) {
|
|||||||
siteManager := content.NewSiteManagerWithAuth(contentClient, cfg.Auth.DevMode, authProvider)
|
siteManager := content.NewSiteManagerWithAuth(contentClient, cfg.Auth.DevMode, authProvider)
|
||||||
|
|
||||||
// Convert config sites to legacy format and register
|
// Convert config sites to legacy format and register
|
||||||
var legacySites []*content.SiteConfig
|
var legacySites []*config.SiteConfig
|
||||||
for _, site := range cfg.Server.Sites {
|
for _, site := range cfg.Server.Sites {
|
||||||
legacySite := &content.SiteConfig{
|
legacySite := &config.SiteConfig{
|
||||||
SiteID: site.SiteID,
|
SiteID: site.SiteID,
|
||||||
Path: site.Path,
|
Path: site.Path,
|
||||||
SourcePath: site.SourcePath,
|
SourcePath: site.SourcePath,
|
||||||
@@ -173,24 +174,25 @@ func runServe(cmd *cobra.Command, args []string) {
|
|||||||
r.Get("/callback", authService.HandleOAuthCallback)
|
r.Get("/callback", authService.HandleOAuthCallback)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Content API routes
|
// Register all Content API routes
|
||||||
router.Route("/api", func(r chi.Router) {
|
contentHandler.RegisterRoutes(router)
|
||||||
// Public routes
|
|
||||||
r.Get("/content/{siteID}/{id}", contentHandler.GetContent)
|
|
||||||
r.Get("/content/{siteID}", contentHandler.GetAllContent)
|
|
||||||
|
|
||||||
// Protected routes (require authentication)
|
// Serve insertr library assets (development only)
|
||||||
r.Group(func(r chi.Router) {
|
if cfg.Auth.DevMode {
|
||||||
r.Use(authService.RequireAuth)
|
router.Get("/insertr.js", func(w http.ResponseWriter, r *http.Request) {
|
||||||
r.Post("/content/{siteID}", contentHandler.CreateContent)
|
w.Header().Set("Content-Type", "application/javascript")
|
||||||
r.Put("/content/{siteID}/{id}", contentHandler.UpdateContent)
|
http.ServeFile(w, r, "./lib/dist/insertr.js")
|
||||||
r.Delete("/content/{siteID}/{id}", contentHandler.DeleteContent)
|
|
||||||
|
|
||||||
// Version management
|
|
||||||
r.Get("/content/{siteID}/{id}/versions", contentHandler.GetContentVersions)
|
|
||||||
r.Post("/content/{siteID}/{id}/rollback/{version}", contentHandler.RollbackContent)
|
|
||||||
})
|
})
|
||||||
|
router.Get("/insertr.min.js", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/javascript")
|
||||||
|
http.ServeFile(w, r, "./lib/dist/insertr.min.js")
|
||||||
})
|
})
|
||||||
|
router.Get("/insertr.css", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "text/css")
|
||||||
|
http.ServeFile(w, r, "./lib/dist/insertr.css")
|
||||||
|
})
|
||||||
|
log.Printf("📦 Serving insertr library assets from ./lib/dist/ (dev mode)")
|
||||||
|
}
|
||||||
|
|
||||||
// Serve static sites
|
// Serve static sites
|
||||||
for _, siteConfig := range siteManager.GetAllSites() {
|
for _, siteConfig := range siteManager.GetAllSites() {
|
||||||
|
|||||||
10
insertr.yaml
10
insertr.yaml
@@ -2,7 +2,7 @@
|
|||||||
# Server and CLI configuration - library manages its own config
|
# Server and CLI configuration - library manages its own config
|
||||||
|
|
||||||
# Global settings
|
# Global settings
|
||||||
dev_mode: false # Development mode (affects server CORS, CLI verbosity)
|
dev_mode: true # Development mode (affects server CORS, CLI verbosity)
|
||||||
|
|
||||||
# Database configuration
|
# Database configuration
|
||||||
database:
|
database:
|
||||||
@@ -66,3 +66,11 @@ auth:
|
|||||||
endpoint: "" # https://auth.example.com/application/o/insertr/
|
endpoint: "" # https://auth.example.com/application/o/insertr/
|
||||||
client_id: "" # insertr-client (OAuth2 client ID from Authentik)
|
client_id: "" # insertr-client (OAuth2 client ID from Authentik)
|
||||||
client_secret: "" # OAuth2 client secret (or use AUTHENTIK_CLIENT_SECRET env var)
|
client_secret: "" # OAuth2 client secret (or use AUTHENTIK_CLIENT_SECRET env var)
|
||||||
|
|
||||||
|
# Library asset configuration
|
||||||
|
library:
|
||||||
|
base_url: "http://localhost:8080" # Base URL for development
|
||||||
|
use_cdn: false # Use CDN in production
|
||||||
|
cdn_base_url: "https://cdn.jsdelivr.net/npm/@insertr/lib"
|
||||||
|
minified: false # Use full version for debugging
|
||||||
|
version: "1.0.0" # Library version
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -92,13 +93,7 @@ func CORSPreflightHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if origin is allowed
|
// Check if origin is allowed
|
||||||
originAllowed := false
|
originAllowed := slices.Contains(allowedOrigins, origin)
|
||||||
for _, allowed := range allowedOrigins {
|
|
||||||
if origin == allowed {
|
|
||||||
originAllowed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if originAllowed {
|
if originAllowed {
|
||||||
w.Header().Set("Access-Control-Allow-Origin", origin)
|
w.Header().Set("Access-Control-Allow-Origin", origin)
|
||||||
|
|||||||
@@ -1,35 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import "time"
|
// Use db package types directly for API responses - no duplication needed
|
||||||
|
// Request models are kept below as they're different (input DTOs)
|
||||||
// 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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Element context for backend ID generation
|
// Element context for backend ID generation
|
||||||
type ElementContext struct {
|
type ElementContext struct {
|
||||||
@@ -55,44 +27,7 @@ type RollbackContentRequest struct {
|
|||||||
RolledBackBy string `json:"rolled_back_by,omitempty"`
|
RolledBackBy string `json:"rolled_back_by,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collection API models
|
// Collection response types also use db package directly
|
||||||
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 request models
|
// Collection request models
|
||||||
type CreateCollectionRequest struct {
|
type CreateCollectionRequest struct {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ type Config struct {
|
|||||||
CLI CLIConfig `yaml:"cli" mapstructure:"cli"`
|
CLI CLIConfig `yaml:"cli" mapstructure:"cli"`
|
||||||
Server ServerConfig `yaml:"server" mapstructure:"server"`
|
Server ServerConfig `yaml:"server" mapstructure:"server"`
|
||||||
Auth AuthConfig `yaml:"auth" mapstructure:"auth"`
|
Auth AuthConfig `yaml:"auth" mapstructure:"auth"`
|
||||||
|
Library LibraryConfig `yaml:"library" mapstructure:"library"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DatabaseConfig struct {
|
type DatabaseConfig struct {
|
||||||
@@ -65,3 +66,11 @@ type DiscoveryConfig struct {
|
|||||||
Containers bool `yaml:"containers" mapstructure:"containers"`
|
Containers bool `yaml:"containers" mapstructure:"containers"`
|
||||||
Individual bool `yaml:"individual" mapstructure:"individual"`
|
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/config"
|
||||||
"github.com/insertr/insertr/internal/db"
|
"github.com/insertr/insertr/internal/db"
|
||||||
"github.com/insertr/insertr/internal/engine"
|
"github.com/insertr/insertr/internal/engine"
|
||||||
|
"maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Type alias for backward compatibility
|
|
||||||
type SiteConfig = config.SiteConfig
|
|
||||||
|
|
||||||
// SiteManager handles registration and enhancement of static sites
|
// SiteManager handles registration and enhancement of static sites
|
||||||
type SiteManager struct {
|
type SiteManager struct {
|
||||||
sites map[string]*SiteConfig
|
sites map[string]*config.SiteConfig
|
||||||
enhancer *Enhancer
|
enhancer *Enhancer
|
||||||
mutex sync.RWMutex
|
mutex sync.RWMutex
|
||||||
devMode bool
|
devMode bool
|
||||||
@@ -29,7 +27,7 @@ type SiteManager struct {
|
|||||||
// NewSiteManager creates a new site manager
|
// NewSiteManager creates a new site manager
|
||||||
func NewSiteManager(contentClient db.ContentRepository, devMode bool) *SiteManager {
|
func NewSiteManager(contentClient db.ContentRepository, devMode bool) *SiteManager {
|
||||||
return &SiteManager{
|
return &SiteManager{
|
||||||
sites: make(map[string]*SiteConfig),
|
sites: make(map[string]*config.SiteConfig),
|
||||||
enhancer: NewDefaultEnhancer(contentClient, ""), // siteID will be set per operation
|
enhancer: NewDefaultEnhancer(contentClient, ""), // siteID will be set per operation
|
||||||
devMode: devMode,
|
devMode: devMode,
|
||||||
contentClient: contentClient,
|
contentClient: contentClient,
|
||||||
@@ -43,7 +41,7 @@ func NewSiteManagerWithAuth(contentClient db.ContentRepository, devMode bool, au
|
|||||||
authProvider = &engine.AuthProvider{Type: "mock"}
|
authProvider = &engine.AuthProvider{Type: "mock"}
|
||||||
}
|
}
|
||||||
return &SiteManager{
|
return &SiteManager{
|
||||||
sites: make(map[string]*SiteConfig),
|
sites: make(map[string]*config.SiteConfig),
|
||||||
contentClient: contentClient,
|
contentClient: contentClient,
|
||||||
authProvider: authProvider,
|
authProvider: authProvider,
|
||||||
devMode: devMode,
|
devMode: devMode,
|
||||||
@@ -51,7 +49,7 @@ func NewSiteManagerWithAuth(contentClient db.ContentRepository, devMode bool, au
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterSite adds a site to the manager
|
// 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()
|
sm.mutex.Lock()
|
||||||
defer sm.mutex.Unlock()
|
defer sm.mutex.Unlock()
|
||||||
|
|
||||||
@@ -90,7 +88,7 @@ func (sm *SiteManager) RegisterSite(config *SiteConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RegisterSites bulk registers multiple sites from configuration
|
// 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 {
|
for _, config := range configs {
|
||||||
if err := sm.RegisterSite(config); err != nil {
|
if err := sm.RegisterSite(config); err != nil {
|
||||||
return fmt.Errorf("failed to register site %s: %w", config.SiteID, err)
|
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
|
// 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()
|
sm.mutex.RLock()
|
||||||
defer sm.mutex.RUnlock()
|
defer sm.mutex.RUnlock()
|
||||||
|
|
||||||
@@ -109,15 +107,13 @@ func (sm *SiteManager) GetSite(siteID string) (*SiteConfig, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAllSites returns all registered sites
|
// GetAllSites returns all registered sites
|
||||||
func (sm *SiteManager) GetAllSites() map[string]*SiteConfig {
|
func (sm *SiteManager) GetAllSites() map[string]*config.SiteConfig {
|
||||||
sm.mutex.RLock()
|
sm.mutex.RLock()
|
||||||
defer sm.mutex.RUnlock()
|
defer sm.mutex.RUnlock()
|
||||||
|
|
||||||
// Return a copy to prevent external modification
|
// Return a copy to prevent external modification
|
||||||
result := make(map[string]*SiteConfig)
|
result := make(map[string]*config.SiteConfig)
|
||||||
for id, site := range sm.sites {
|
maps.Copy(result, sm.sites)
|
||||||
result[id] = site
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +185,7 @@ func (sm *SiteManager) EnhanceSite(siteID string) error {
|
|||||||
// EnhanceAllSites enhances all registered sites that have auto-enhancement enabled
|
// EnhanceAllSites enhances all registered sites that have auto-enhancement enabled
|
||||||
func (sm *SiteManager) EnhanceAllSites() error {
|
func (sm *SiteManager) EnhanceAllSites() error {
|
||||||
sm.mutex.RLock()
|
sm.mutex.RLock()
|
||||||
sites := make([]*SiteConfig, 0, len(sm.sites))
|
sites := make([]*config.SiteConfig, 0, len(sm.sites))
|
||||||
for _, site := range sm.sites {
|
for _, site := range sm.sites {
|
||||||
if site.AutoEnhance {
|
if site.AutoEnhance {
|
||||||
sites = append(sites, site)
|
sites = append(sites, site)
|
||||||
@@ -212,7 +208,7 @@ func (sm *SiteManager) EnhanceAllSites() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetStats returns statistics about registered sites
|
// GetStats returns statistics about registered sites
|
||||||
func (sm *SiteManager) GetStats() map[string]interface{} {
|
func (sm *SiteManager) GetStats() map[string]any {
|
||||||
sm.mutex.RLock()
|
sm.mutex.RLock()
|
||||||
defer sm.mutex.RUnlock()
|
defer sm.mutex.RUnlock()
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ContentRepository interface for accessing content data
|
// ContentRepository interface for accessing content data
|
||||||
// This replaces the ContentClient interface from engine package
|
|
||||||
type ContentRepository interface {
|
type ContentRepository interface {
|
||||||
GetContent(ctx context.Context, siteID, contentID string) (*ContentItem, error)
|
GetContent(ctx context.Context, siteID, contentID string) (*ContentItem, error)
|
||||||
GetBulkContent(ctx context.Context, siteID string, contentIDs []string) (map[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(),
|
idGenerator: NewIDGenerator(),
|
||||||
client: client,
|
client: client,
|
||||||
authProvider: authProvider,
|
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(),
|
idGenerator: NewIDGenerator(),
|
||||||
client: client,
|
client: client,
|
||||||
authProvider: authProvider,
|
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)
|
// 6. Inject editor assets for enhancement mode (development)
|
||||||
if input.Mode == Enhancement {
|
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, "")
|
injector.InjectEditorAssets(doc, true, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,7 +601,7 @@ func (e *ContentEngine) reconstructCollectionItems(collectionNode *html.Node, co
|
|||||||
|
|
||||||
if structuralBody != nil {
|
if structuralBody != nil {
|
||||||
// Process each .insertr element using Injector pattern (unified approach)
|
// 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
|
// Walk through structural elements and hydrate with content from content table
|
||||||
e.walkNodes(structuralBody, func(n *html.Node) {
|
e.walkNodes(structuralBody, func(n *html.Node) {
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/insertr/insertr/internal/config"
|
||||||
"github.com/insertr/insertr/internal/db"
|
"github.com/insertr/insertr/internal/db"
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Injector handles content injection into HTML elements
|
// Injector handles content injection into HTML elements
|
||||||
@@ -15,19 +17,21 @@ type Injector struct {
|
|||||||
client db.ContentRepository
|
client db.ContentRepository
|
||||||
siteID string
|
siteID string
|
||||||
authProvider *AuthProvider
|
authProvider *AuthProvider
|
||||||
|
config *config.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInjector creates a new content injector
|
// 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{
|
return &Injector{
|
||||||
client: client,
|
client: client,
|
||||||
siteID: siteID,
|
siteID: siteID,
|
||||||
authProvider: &AuthProvider{Type: "mock"}, // default
|
authProvider: &AuthProvider{Type: "mock"}, // default
|
||||||
|
config: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInjectorWithAuth creates a new content injector with auth provider
|
// 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 {
|
if authProvider == nil {
|
||||||
authProvider = &AuthProvider{Type: "mock"}
|
authProvider = &AuthProvider{Type: "mock"}
|
||||||
}
|
}
|
||||||
@@ -35,6 +39,7 @@ func NewInjectorWithAuth(client db.ContentRepository, siteID string, authProvide
|
|||||||
client: client,
|
client: client,
|
||||||
siteID: siteID,
|
siteID: siteID,
|
||||||
authProvider: authProvider,
|
authProvider: authProvider,
|
||||||
|
config: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +205,7 @@ func (i *Injector) setAttribute(node *html.Node, key, value string) {
|
|||||||
// Remove existing attribute if present
|
// Remove existing attribute if present
|
||||||
for idx, attr := range node.Attr {
|
for idx, attr := range node.Attr {
|
||||||
if attr.Key == key {
|
if attr.Key == key {
|
||||||
node.Attr = append(node.Attr[:idx], node.Attr[idx+1:]...)
|
node.Attr = slices.Delete(node.Attr, idx, idx+1)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,11 +237,9 @@ func (i *Injector) addClass(node *html.Node, className string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if class already exists
|
// Check if class already exists
|
||||||
for _, class := range classes {
|
if slices.Contains(classes, className) {
|
||||||
if class == className {
|
|
||||||
return // Class already exists
|
return // Class already exists
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Add new class
|
// Add new class
|
||||||
classes = append(classes, className)
|
classes = append(classes, className)
|
||||||
@@ -327,8 +330,15 @@ func (i *Injector) InjectEditorScript(doc *html.Node) {
|
|||||||
if i.authProvider != nil {
|
if i.authProvider != nil {
|
||||||
authProvider = i.authProvider.Type
|
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
|
// Parse and inject the CSS and script elements
|
||||||
insertrDoc, err := html.Parse(strings.NewReader(insertrHTML))
|
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")
|
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
|
// injectAllHeadElements finds and injects all head elements (link, script) from parsed HTML
|
||||||
func (i *Injector) injectAllHeadElements(doc *html.Node, targetNode *html.Node) error {
|
func (i *Injector) injectAllHeadElements(doc *html.Node, targetNode *html.Node) error {
|
||||||
elements := i.findAllHeadElements(doc)
|
elements := i.findAllHeadElements(doc)
|
||||||
@@ -479,15 +457,69 @@ func (i *Injector) extractElementByClass(node *html.Node, className string) *htm
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractElementByTag finds element with specific tag
|
// getLibraryURL returns the appropriate URL for library assets (CSS/JS)
|
||||||
func (i *Injector) extractElementByTag(node *html.Node, tagName string) *html.Node {
|
func (i *Injector) getLibraryURL(filename string) string {
|
||||||
if node.Type == html.ElementNode && node.Data == tagName {
|
if i.config == nil {
|
||||||
return node
|
// 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 {
|
// Check if we should use CDN
|
||||||
return result
|
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 ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,26 +21,7 @@ try {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Copy built library to unified binary assets
|
// 2. Build the unified binary
|
||||||
console.log('📁 Copying library to unified binary assets...');
|
|
||||||
const srcDir = './lib/dist';
|
|
||||||
const destDir = './internal/content/assets';
|
|
||||||
|
|
||||||
// Ensure destination directory exists
|
|
||||||
fs.mkdirSync(destDir, { recursive: true });
|
|
||||||
|
|
||||||
// Copy files
|
|
||||||
const files = fs.readdirSync(srcDir);
|
|
||||||
files.forEach(file => {
|
|
||||||
const src = path.join(srcDir, file);
|
|
||||||
const dest = path.join(destDir, file);
|
|
||||||
fs.copyFileSync(src, dest);
|
|
||||||
console.log(` ✅ Copied ${file}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('📁 Assets copied successfully\n');
|
|
||||||
|
|
||||||
// 3. Build the unified binary
|
|
||||||
console.log('🔧 Building unified Insertr binary...');
|
console.log('🔧 Building unified Insertr binary...');
|
||||||
try {
|
try {
|
||||||
execSync('go build -o insertr .', { stdio: 'inherit' });
|
execSync('go build -o insertr .', { stdio: 'inherit' });
|
||||||
|
|||||||
Reference in New Issue
Block a user