884 lines
32 KiB
HTML
884 lines
32 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
GKACHELE™ SaaS Professional Customizer - STUDIO EDITION
|
|
Restored Dark Pro Aesthetic + Advanced Grid Logic (V4.2)
|
|
-->
|
|
<html lang="es">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Studio Builder - {{ site_name or 'Sitio' }} | GKACHELE™</title>
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
|
<link
|
|
href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;800&family=Inter:wght@400;500;700&display=swap"
|
|
rel="stylesheet">
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Sortable/1.15.0/Sortable.min.js"></script>
|
|
<style>
|
|
:root {
|
|
--gk-admin-bar: #0f172a;
|
|
--gk-sidebar-bg: #1e293b;
|
|
--gk-item-bg: #334155;
|
|
--gk-white: #ffffff;
|
|
--gk-border: #334155;
|
|
--gk-text: #f8fafc;
|
|
--gk-text-muted: #94a3b8;
|
|
--gk-accent: #38bdf8;
|
|
--gk-accent-hover: #7dd3fc;
|
|
--transition: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Inter', sans-serif;
|
|
background: #020617;
|
|
color: var(--gk-text);
|
|
overflow: hidden;
|
|
height: 100vh;
|
|
}
|
|
|
|
/* LAYOUT */
|
|
.studio-overlay {
|
|
display: flex;
|
|
height: 100vh;
|
|
}
|
|
|
|
/* SIDEBAR (Original Dark) */
|
|
.sidebar {
|
|
width: 320px;
|
|
background: var(--gk-sidebar-bg);
|
|
border-right: 1px solid var(--gk-border);
|
|
display: flex;
|
|
flex-direction: column;
|
|
z-index: 100;
|
|
box-shadow: 10px 0 30px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.sidebar-header {
|
|
height: 70px;
|
|
padding: 0 24px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
border-bottom: 1px solid var(--gk-border);
|
|
background: var(--gk-admin-bar);
|
|
}
|
|
|
|
.logo {
|
|
font-family: 'Outfit', sans-serif;
|
|
font-weight: 800;
|
|
font-size: 18px;
|
|
color: var(--gk-accent);
|
|
}
|
|
|
|
.plan-tag {
|
|
font-size: 10px;
|
|
font-weight: 800;
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
background: rgba(56, 189, 248, 0.1);
|
|
color: var(--gk-accent);
|
|
}
|
|
|
|
.sidebar-scroll {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding-bottom: 80px;
|
|
}
|
|
|
|
/* ACCORDION */
|
|
.section-title {
|
|
padding: 18px 24px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
font-weight: 600;
|
|
font-size: 13px;
|
|
color: var(--gk-text-muted);
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.02);
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.section-title:hover {
|
|
background: var(--gk-item-bg);
|
|
color: var(--gk-white);
|
|
}
|
|
|
|
.section-title i {
|
|
color: var(--gk-accent);
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.section-content {
|
|
display: none;
|
|
padding: 24px;
|
|
background: #0f172a;
|
|
border-bottom: 1px solid var(--gk-border);
|
|
}
|
|
|
|
.section-content.active {
|
|
display: block;
|
|
animation: fadeIn 0.3s;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from {
|
|
opacity: 0;
|
|
transform: translateY(-10px);
|
|
}
|
|
|
|
to {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
}
|
|
|
|
/* INPUTS */
|
|
.label {
|
|
display: block;
|
|
font-size: 10px;
|
|
font-weight: 800;
|
|
color: var(--gk-text-muted);
|
|
text-transform: uppercase;
|
|
margin-bottom: 8px;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
input,
|
|
textarea,
|
|
select {
|
|
width: 100%;
|
|
border-radius: 8px;
|
|
background: #1e293b;
|
|
border: 1px solid #334155;
|
|
padding: 10px 14px;
|
|
color: white;
|
|
font-size: 13px;
|
|
margin-bottom: 16px;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
input:focus {
|
|
border-color: var(--gk-accent);
|
|
outline: none;
|
|
box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
|
|
}
|
|
|
|
/* GRID CANVAS (DEMO STYLE) */
|
|
.studio-main {
|
|
flex: 1;
|
|
background: #020617;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
padding: 40px;
|
|
position: relative;
|
|
}
|
|
|
|
.frame-wrapper {
|
|
flex: 1;
|
|
max-width: 1200px;
|
|
width: 100%;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
box-shadow: 0 50px 100px -20px rgba(0, 0, 0, 0.8);
|
|
overflow: hidden;
|
|
position: relative;
|
|
display: flex;
|
|
flex-direction: column;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.frame-header {
|
|
height: 32px;
|
|
background: #e2e8f0;
|
|
border-bottom: 1px solid #cbd5e1;
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 0 12px;
|
|
gap: 8px;
|
|
}
|
|
|
|
.dot {
|
|
width: 10px;
|
|
height: 10px;
|
|
border-radius: 50%;
|
|
opacity: 0.6;
|
|
}
|
|
|
|
.red {
|
|
background: #ff5f56;
|
|
}
|
|
|
|
.yellow {
|
|
background: #ffbd2e;
|
|
}
|
|
|
|
.green {
|
|
background: #27c93f;
|
|
}
|
|
|
|
.frame-content {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
background: #f5f5f7;
|
|
position: relative;
|
|
padding: 40px;
|
|
}
|
|
|
|
/* THE ADVANCED GRID */
|
|
.grid-canvas {
|
|
display: grid;
|
|
grid-template-columns: repeat(4, 1fr);
|
|
gap: 20px;
|
|
min-height: 400px;
|
|
background: rgba(255, 121, 33, 0.05);
|
|
border-radius: 12px;
|
|
border: 2px dashed #fa7921;
|
|
padding: 24px;
|
|
}
|
|
|
|
.block-card {
|
|
background: white;
|
|
border: 1px solid #e2e8f0;
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
position: relative;
|
|
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
|
|
transition: var(--transition);
|
|
cursor: grab;
|
|
}
|
|
|
|
.block-card:hover {
|
|
border-color: var(--gk-accent);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.block-card.dragging {
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.block-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 12px;
|
|
border-bottom: 1px solid #f1f5f9;
|
|
padding-bottom: 8px;
|
|
}
|
|
|
|
.block-name {
|
|
font-size: 11px;
|
|
font-weight: 800;
|
|
color: #94a3b8;
|
|
text-transform: uppercase;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
}
|
|
|
|
.block-ctrls {
|
|
display: flex;
|
|
gap: 4px;
|
|
}
|
|
|
|
.ctrl-btn {
|
|
width: 24px;
|
|
height: 24px;
|
|
border-radius: 6px;
|
|
border: none;
|
|
background: #f1f5f9;
|
|
color: #64748b;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 10px;
|
|
}
|
|
|
|
.ctrl-btn:hover {
|
|
background: var(--gk-accent);
|
|
color: #020617;
|
|
}
|
|
|
|
.resize-handle {
|
|
position: absolute;
|
|
right: -5px;
|
|
bottom: -5px;
|
|
width: 20px;
|
|
height: 20px;
|
|
cursor: se-resize;
|
|
z-index: 10;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.resize-handle::after {
|
|
content: '';
|
|
width: 6px;
|
|
height: 6px;
|
|
border-right: 2px solid #cbd5e1;
|
|
border-bottom: 2px solid #cbd5e1;
|
|
}
|
|
|
|
.block-card:hover .resize-handle::after {
|
|
border-color: var(--gk-accent);
|
|
}
|
|
|
|
/* BUTTONS */
|
|
.btn {
|
|
padding: 12px 20px;
|
|
border-radius: 10px;
|
|
font-weight: 700;
|
|
cursor: pointer;
|
|
font-size: 13px;
|
|
text-decoration: none;
|
|
border: none;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 8px;
|
|
transition: var(--transition);
|
|
}
|
|
|
|
.btn-primary {
|
|
background: var(--gk-accent);
|
|
color: #020617;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: var(--gk-accent-hover);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.btn-ghost {
|
|
background: transparent;
|
|
border: 1px solid #334155;
|
|
color: var(--gk-text-muted);
|
|
}
|
|
|
|
.btn-ghost:hover {
|
|
border-color: var(--gk-accent);
|
|
color: white;
|
|
}
|
|
|
|
/* FOOTER ACTIONS */
|
|
.footer-actions {
|
|
position: absolute;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
height: 80px;
|
|
background: var(--gk-admin-bar);
|
|
border-top: 1px solid var(--gk-border);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0 24px;
|
|
}
|
|
|
|
/* MODALS */
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
inset: 0;
|
|
background: rgba(0, 0, 0, 0.8);
|
|
backdrop-filter: blur(10px);
|
|
z-index: 2000;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.modal.active {
|
|
display: flex;
|
|
}
|
|
|
|
.modal-box {
|
|
width: 90%;
|
|
max-width: 500px;
|
|
background: white;
|
|
border-radius: 20px;
|
|
overflow: hidden;
|
|
color: #1e293b;
|
|
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
.modal-head {
|
|
padding: 20px 24px;
|
|
background: #f8fafc;
|
|
border-bottom: 1px solid #e2e8f0;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.modal-body {
|
|
padding: 24px;
|
|
}
|
|
|
|
.modal-foot {
|
|
padding: 16px 24px;
|
|
background: #f8fafc;
|
|
border-top: 1px solid #e2e8f0;
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 12px;
|
|
}
|
|
|
|
/* RESPONSIVE TOGGLES */
|
|
.device-bar {
|
|
position: absolute;
|
|
top: -50px;
|
|
left: 50%;
|
|
transform: translateX(-50%);
|
|
display: flex;
|
|
gap: 20px;
|
|
z-index: 1000;
|
|
}
|
|
|
|
.device-icon {
|
|
color: #94a3b8;
|
|
cursor: pointer;
|
|
transition: 0.3s;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.device-icon:hover,
|
|
.device-icon.active {
|
|
color: var(--gk-accent);
|
|
transform: scale(1.2);
|
|
}
|
|
|
|
.block-count-bar {
|
|
height: 4px;
|
|
background: #334155;
|
|
border-radius: 2px;
|
|
margin-top: 8px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.block-progress {
|
|
height: 100%;
|
|
background: var(--gk-accent);
|
|
transition: 0.3s;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="studio-overlay">
|
|
<!-- SIDEBAR -->
|
|
<div class="sidebar">
|
|
<div class="sidebar-header">
|
|
<div class="logo">GKACHELE™ STUDIO</div>
|
|
<div class="plan-tag" id="plan-display">{{ user_plan|upper }}</div>
|
|
</div>
|
|
|
|
<div class="sidebar-scroll">
|
|
<!-- IDENTIDAD -->
|
|
<div class="section-title" onclick="toggleAccordion(this)">
|
|
<span><i class="fa-solid fa-id-card"></i> Identidad del Sitio</span>
|
|
<i class="fa-solid fa-chevron-right"></i>
|
|
</div>
|
|
<div class="section-content">
|
|
<span class="label">Nombre del Sitio</span>
|
|
<input type="text" id="site_name" value="{{ content.site_name or '' }}"
|
|
oninput="updatePreviewCore()">
|
|
<span class="label">Título Principal</span>
|
|
<input type="text" id="hero_title" value="{{ content.hero_title or '' }}"
|
|
oninput="updatePreviewCore()">
|
|
<span class="label">Descripción</span>
|
|
<textarea id="hero_description" rows="3"
|
|
oninput="updatePreviewCore()">{{ content.hero_description or '' }}</textarea>
|
|
</div>
|
|
|
|
<!-- DISEÑO -->
|
|
<div class="section-title" onclick="toggleAccordion(this)">
|
|
<span><i class="fa-solid fa-palette"></i> Estilo & Multimedia</span>
|
|
<i class="fa-solid fa-chevron-right"></i>
|
|
</div>
|
|
<div class="section-content">
|
|
<span class="label">Color Principal</span>
|
|
<div style="display: flex; gap:10px; align-items: center;">
|
|
<input type="color" id="color_primary"
|
|
value="{{ content.colors.primary if content.colors else '#38bdf8' }}"
|
|
style="width: 50px; padding: 2px;" oninput="updatePreviewCore()">
|
|
<input type="text" id="color_text_val"
|
|
value="{{ content.colors.primary if content.colors else '#38bdf8' }}"
|
|
style="flex:1; margin-bottom:0">
|
|
</div>
|
|
<div style="margin-top: 20px;">
|
|
<span class="label">Fondo Premium (Video/IMG)</span>
|
|
<select id="bg_type" onchange="updatePreviewCore()">
|
|
<option value="none">Por Defecto</option>
|
|
<option value="image" {{ 'selected' if content.premium_bg and
|
|
content.premium_bg.type=='image' }}>Imagen HD</option>
|
|
<option value="video" {{ 'selected' if content.premium_bg and
|
|
content.premium_bg.type=='video' }}>Video Cinematic</option>
|
|
</select>
|
|
<input type="url" id="bg_url" placeholder="URL del recurso..."
|
|
value="{{ content.premium_bg.url if content.premium_bg else '' }}"
|
|
oninput="updatePreviewCore()">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- CONTACTO -->
|
|
<div class="section-title" onclick="toggleAccordion(this)">
|
|
<span><i class="fa-solid fa-location-dot"></i> Contacto & WhatsApp</span>
|
|
<i class="fa-solid fa-chevron-right"></i>
|
|
</div>
|
|
<div class="section-content">
|
|
<span class="label">WhatsApp</span>
|
|
<input type="tel" id="redes_whatsapp" placeholder="34600000000"
|
|
value="{{ content.redes_sociales.whatsapp if content.redes_sociales else '' }}"
|
|
oninput="updatePreviewCore()">
|
|
<span class="label">Dirección (Google Maps)</span>
|
|
<input type="text" id="direccion" value="{{ content.direccion or '' }}"
|
|
oninput="updatePreviewCore()">
|
|
</div>
|
|
|
|
<!-- BLOQUES (DEMO PANEL) -->
|
|
<div class="section-title" onclick="toggleAccordion(this)">
|
|
<span><i class="fa-solid fa-cubes"></i> Biblioteca de Bloques</span>
|
|
<i class="fa-solid fa-chevron-right"></i>
|
|
</div>
|
|
<div class="section-content">
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
|
|
<div class="btn btn-ghost" onclick="addNewBlock('texto')" style="font-size: 11px;"><i
|
|
class="fa-solid fa-font"></i> Texto</div>
|
|
<div class="btn btn-ghost" onclick="addNewBlock('imagen')" style="font-size: 11px;"><i
|
|
class="fa-solid fa-image"></i> Imagen</div>
|
|
<div class="btn btn-ghost" onclick="addNewBlock('video')" style="font-size: 11px;"><i
|
|
class="fa-solid fa-play"></i> Video</div>
|
|
<div class="btn btn-ghost" onclick="addNewBlock('mapa')" style="font-size: 11px;"><i
|
|
class="fa-solid fa-map"></i> Mapa</div>
|
|
</div>
|
|
<div style="margin-top: 20px;">
|
|
<div style="display: flex; justify-content: space-between; font-size: 11px;">
|
|
<span>Uso de Bloques</span>
|
|
<span id="counter-txt">0/10</span>
|
|
</div>
|
|
<div class="block-count-bar">
|
|
<div class="block-progress" id="count-bar" style="width: 0%"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% if user_rubro == 'restaurante' %}
|
|
<div class="section-title" onclick="gestionarPlatosMenu()">
|
|
<span><i class="fa-solid fa-utensils"></i> Menú Restaurante</span>
|
|
<i class="fa-solid fa-up-right-from-square" style="font-size: 10px;"></i>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="footer-actions">
|
|
<button class="btn btn-ghost" onclick="window.location.reload()">Descartar cambios</button>
|
|
<button class="btn btn-primary" onclick="publishSite()">Publicar Cambios</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- MAIN CANVAS (BUILDER AREA) -->
|
|
<div class="studio-main">
|
|
<div class="device-bar">
|
|
<i class="fa-solid fa-desktop device-icon active" onclick="setStudioDevice('desktop', this)"></i>
|
|
<i class="fa-solid fa-tablet-screen-button device-icon" onclick="setStudioDevice('tablet', this)"></i>
|
|
<i class="fa-solid fa-mobile-screen-button device-icon" onclick="setStudioDevice('mobile', this)"></i>
|
|
</div>
|
|
|
|
<div class="frame-wrapper" id="studio-frame">
|
|
<div class="frame-header">
|
|
<div class="dot red"></div>
|
|
<div class="dot yellow"></div>
|
|
<div class="dot green"></div>
|
|
<div style="margin-left: 20px; font-size: 11px; color: #94a3b8;">{{ slug }}.gkachele.com</div>
|
|
</div>
|
|
<div class="frame-content">
|
|
<!-- GRID CANVAS AS SEEN IN SAAS-DEMO -->
|
|
<div class="grid-canvas" id="block-canvas">
|
|
<!-- Blocks injected here -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- HIDDEN ACTUAL IFRAME (For final publish preview) -->
|
|
<iframe id="preview-worker" src="/api/customizer/preview-frame/{{ site_id }}" style="display:none"></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- BLOCK EDIT MODAL -->
|
|
<div class="modal" id="editModal">
|
|
<div class="modal-box">
|
|
<div class="modal-head">
|
|
<h3 id="edit-title">Editar Bloque</h3>
|
|
<i class="fa-solid fa-xmark" onclick="closeModal()" style="cursor:pointer"></i>
|
|
</div>
|
|
<div class="modal-body" id="edit-body">
|
|
<!-- Dynamic Form -->
|
|
</div>
|
|
<div class="modal-foot">
|
|
<button class="btn btn-ghost" onclick="closeModal()">Cancelar</button>
|
|
<button class="btn btn-primary" onclick="saveEdit()">Guardar Cambios</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- PLATOS MODAL -->
|
|
<div class="modal" id="platosModal">
|
|
<div class="modal-box" style="max-width: 650px;">
|
|
<div class="modal-head">
|
|
<h3>Gestor de Platos</h3>
|
|
<i class="fa-solid fa-xmark" onclick="document.getElementById('platosModal').classList.remove('active')"
|
|
style="cursor:pointer"></i>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px;">
|
|
<input type="text" id="p-nombre" placeholder="Nombre">
|
|
<select id="p-cat">
|
|
<option value="Entrantes">Entrantes</option>
|
|
<option value="Principales">Principales</option>
|
|
<option value="Postres">Postres</option>
|
|
</select>
|
|
</div>
|
|
<textarea id="p-desc" placeholder="Descripción..."></textarea>
|
|
<input type="text" id="p-precio" placeholder="Precio ($)">
|
|
<button class="btn btn-primary" style="width: 100%;" onclick="addPlato()">Añadir Plato</button>
|
|
<hr style="margin: 20px 0; border: none; border-top: 1px solid #eee;">
|
|
<div id="platos-list" style="max-height: 250px; overflow-y: auto;"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// INITIAL APP STATE
|
|
const App = {
|
|
siteId: {{ site_id }},
|
|
plan: "{{ user_plan }}",
|
|
rubro: "{{ user_rubro }}",
|
|
blocks: [],
|
|
menuItems: { },
|
|
editingId: null,
|
|
planLimits: { starter: 10, pro: 50, premium: 9999, base: 10 }
|
|
};
|
|
|
|
// Load initial data
|
|
{% if content.blocks %} App.blocks = {{ content.blocks | tojson | safe }}; {% endif %}
|
|
{% if content.menu_items %} App.menuItems = {{ content.menu_items | tojson | safe }}; {% endif %}
|
|
|
|
function toggleAccordion(el) {
|
|
const content = el.nextElementSibling;
|
|
const icon = el.querySelector('.fa-chevron-right');
|
|
document.querySelectorAll('.section-content').forEach(c => { if (c !== content) c.classList.remove('active'); });
|
|
document.querySelectorAll('.section-title i.fa-chevron-right').forEach(i => { if (i !== icon) i.style.transform = 'rotate(0deg)'; });
|
|
content.classList.toggle('active');
|
|
icon.style.transform = content.classList.contains('active') ? 'rotate(90deg)' : 'rotate(0deg)';
|
|
}
|
|
|
|
function renderStudioBlocks() {
|
|
const canvas = document.getElementById('block-canvas');
|
|
if (App.blocks.length === 0) {
|
|
canvas.innerHTML = `<div style="grid-column: 1/-1; text-align: center; color: #94a3b8; padding: 60px;">
|
|
<i class="fa-solid fa-arrow-pointer" style="font-size: 40px; margin-bottom: 10px; opacity:0.3"></i>
|
|
<p>Usa la biblioteca de bloques para construir tu página</p>
|
|
</div>`;
|
|
updateCounter();
|
|
return;
|
|
}
|
|
|
|
canvas.innerHTML = App.blocks.map((b, i) => `
|
|
<div class="block-card" style="grid-column: span ${b.colSpan || 1}" data-id="${b.id}">
|
|
<div class="block-header">
|
|
<div class="block-name"><i class="${getIcon(b.type)}"></i> ${b.type}</div>
|
|
<div class="block-ctrls">
|
|
<button class="ctrl-btn" onclick="openEdit(${i})"><i class="fa-solid fa-pen"></i></button>
|
|
<button class="ctrl-btn" onclick="deleteBlock(${i})"><i class="fa-solid fa-trash"></i></button>
|
|
</div>
|
|
</div>
|
|
<div style="font-size: 11px; color: #64748b;">${getBrief(b)}</div>
|
|
<div class="resize-handle" onmousedown="handleResize(event, ${i})"></div>
|
|
</div>
|
|
`).join('');
|
|
|
|
initSortable();
|
|
updateCounter();
|
|
}
|
|
|
|
function getIcon(t) {
|
|
const maps = { texto: 'fa-solid fa-font', imagen: 'fa-solid fa-image', video: 'fa-solid fa-play', mapa: 'fa-solid fa-map' };
|
|
return maps[t] || 'fa-solid fa-cube';
|
|
}
|
|
|
|
function getBrief(b) {
|
|
if (b.type === 'texto') return (b.content.titulo || 'Sin título').substring(0, 20);
|
|
return (b.content.url || 'Sin recurso').substring(0, 25) + '...';
|
|
}
|
|
|
|
function updateCounter() {
|
|
const limit = App.planLimits[App.plan] || 10;
|
|
const count = App.blocks.length;
|
|
document.getElementById('counter-txt').innerText = `${count}/${limit}`;
|
|
document.getElementById('count-bar').style.width = `${(count / limit) * 100}%`;
|
|
}
|
|
|
|
function addNewBlock(type) {
|
|
const limit = App.planLimits[App.plan] || 10;
|
|
if (App.blocks.length >= limit) {
|
|
alert(`Límite de ${limit} bloques alcanzado para el plan ${App.plan.toUpperCase()}`);
|
|
return;
|
|
}
|
|
const b = { id: 'b_' + Date.now(), type, content: {}, colSpan: 1, order: App.blocks.length };
|
|
App.blocks.push(b);
|
|
renderStudioBlocks();
|
|
updatePreviewCore();
|
|
}
|
|
|
|
function openEdit(idx) {
|
|
App.editingId = idx;
|
|
const b = App.blocks[idx];
|
|
const body = document.getElementById('edit-body');
|
|
document.getElementById('edit-title').innerText = `Opciones de ${b.type}`;
|
|
|
|
let form = '';
|
|
if (b.type === 'texto') {
|
|
form = `<span class="label">Título</span><input type="text" id="e-title" value="${b.content.titulo || ''}">
|
|
<span class="label">Contenido HTML/Texto</span><textarea id="e-cont" rows="6" style="color:#000; background:#fff;">${b.content.contenido || ''}</textarea>`;
|
|
} else {
|
|
form = `<span class="label">URL Recurso</span><input type="text" id="e-url" value="${b.content.url || ''}" style="color:#000; background:#fff;">`;
|
|
}
|
|
body.innerHTML = form;
|
|
document.getElementById('editModal').classList.add('active');
|
|
}
|
|
|
|
function saveEdit() {
|
|
const b = App.blocks[App.editingId];
|
|
if (b.type === 'texto') {
|
|
b.content.titulo = document.getElementById('e-title').value;
|
|
b.content.contenido = document.getElementById('e-cont').value;
|
|
} else {
|
|
b.content.url = document.getElementById('e-url').value;
|
|
}
|
|
closeModal();
|
|
renderStudioBlocks();
|
|
updatePreviewCore();
|
|
}
|
|
|
|
function closeModal() { document.getElementById('editModal').classList.remove('active'); }
|
|
|
|
function deleteBlock(idx) { if (confirm('¿Eliminar bloque?')) { App.blocks.splice(idx, 1); renderStudioBlocks(); updatePreviewCore(); } }
|
|
|
|
function handleResize(e, idx) {
|
|
e.preventDefault(); e.stopPropagation();
|
|
const startX = e.clientX;
|
|
const card = document.querySelector(`[data-id="${App.blocks[idx].id}"]`);
|
|
const startSpan = App.blocks[idx].colSpan || 1;
|
|
|
|
function onMove(ev) {
|
|
const delta = ev.clientX - startX;
|
|
const change = Math.round(delta / 250); // Column width approx
|
|
let newSpan = Math.max(1, Math.min(4, startSpan + change));
|
|
card.style.gridColumn = `span ${newSpan}`;
|
|
}
|
|
function onUp(ev) {
|
|
const delta = ev.clientX - startX;
|
|
const change = Math.round(delta / 250);
|
|
App.blocks[idx].colSpan = Math.max(1, Math.min(4, startSpan + change));
|
|
renderStudioBlocks();
|
|
updatePreviewCore();
|
|
document.removeEventListener('mousemove', onMove);
|
|
document.removeEventListener('mouseup', onUp);
|
|
}
|
|
document.addEventListener('mousemove', onMove);
|
|
document.addEventListener('mouseup', onUp);
|
|
}
|
|
|
|
function initSortable() {
|
|
const el = document.getElementById('block-canvas');
|
|
Sortable.create(el, {
|
|
animation: 150, onEnd: () => {
|
|
const newOrder = Array.from(el.children).map(c => c.dataset.id);
|
|
App.blocks = newOrder.map(id => App.blocks.find(b => b.id === id)).filter(x => x);
|
|
updatePreviewCore();
|
|
}
|
|
});
|
|
}
|
|
|
|
function setStudioDevice(device, btn) {
|
|
const frame = document.getElementById('studio-frame');
|
|
document.querySelectorAll('.device-icon').forEach(i => i.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
if (device === 'desktop') { frame.style.width = '1200px'; frame.style.maxWidth = '100%'; }
|
|
if (device === 'tablet') { frame.style.width = '768px'; frame.style.maxWidth = '90%'; }
|
|
if (device === 'mobile') { frame.style.width = '375px'; frame.style.maxWidth = '80%'; }
|
|
}
|
|
|
|
function getFinalData() {
|
|
return {
|
|
site_name: document.getElementById('site_name').value,
|
|
hero_title: document.getElementById('hero_title').value,
|
|
hero_description: document.getElementById('hero_description').value,
|
|
direccion: document.getElementById('direccion').value,
|
|
redes_sociales: { whatsapp: document.getElementById('redes_whatsapp').value },
|
|
colors: { primary: document.getElementById('color_primary').value },
|
|
premium_bg: { type: document.getElementById('bg_type').value, url: document.getElementById('bg_url').value },
|
|
blocks: App.blocks,
|
|
menu_items: App.menuItems
|
|
};
|
|
}
|
|
|
|
function updatePreviewCore() {
|
|
const data = getFinalData();
|
|
const worker = document.getElementById('preview-worker');
|
|
worker.contentWindow.postMessage({ type: 'update-content', content: data }, '*');
|
|
}
|
|
|
|
function publishSite() {
|
|
const btn = document.querySelector('.btn-primary');
|
|
btn.innerText = 'Subiendo...'; btn.disabled = true;
|
|
|
|
fetch('/api/customizer/save', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ site_id: App.siteId, content: getFinalData() })
|
|
}).then(r => r.json()).then(res => {
|
|
if (res.success) { alert('🚀 Sitio Publicado'); window.location.href = '/dashboard'; }
|
|
else alert('Error: ' + res.error);
|
|
}).finally(() => { btn.innerText = 'Publicar Cambios'; btn.disabled = false; });
|
|
}
|
|
|
|
// MENU LOGIC
|
|
function gestionarPlatosMenu() {
|
|
renderPlatos();
|
|
document.getElementById('platosModal').classList.add('active');
|
|
}
|
|
function renderPlatos() {
|
|
const list = document.getElementById('platos-list');
|
|
list.innerHTML = Object.entries(App.menuItems).map(([id, p]) => `
|
|
<div style="background: #f8fafc; padding: 12px; border-radius: 10px; margin-bottom: 8px; display: flex; justify-content: space-between; color:#000;">
|
|
<div><strong>${p.nombre}</strong><br><small>${p.precio} $</small></div>
|
|
<button onclick="deletePlato('${id}')" style="border:none; color:red; cursor:pointer">Eliminar</button>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
function addPlato() {
|
|
const id = 'p_' + Date.now();
|
|
App.menuItems[id] = { nombre: document.getElementById('p-nombre').value, categoria: document.getElementById('p-cat').value, descripcion: document.getElementById('p-desc').value, precio: document.getElementById('p-precio').value };
|
|
renderPlatos();
|
|
updatePreviewCore();
|
|
}
|
|
function deletePlato(id) { delete App.menuItems[id]; renderPlatos(); updatePreviewCore(); }
|
|
|
|
window.onload = () => { renderStudioBlocks(); };
|
|
</script>
|
|
</body>
|
|
|
|
</html> |