formforge-geostudio / builder.html
mapolanski's picture
Onde esta tudo o que eu pedi? So apareceu um botao enviar dados e alguns textos. O sistemas que quero é um gerador de formularios e nao um formulario apenas
b2363b3 verified
Raw History Blame Contribute Delete
25.9 kB
<!DOCTYPE html>
<html lang="pt-BR" class="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>geoForms Studio - Builder</title>
<link rel="icon" type="image/x-icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2'><path d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/><circle cx='12' cy='10' r='3'/></svg>">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script src="https://unpkg.com/feather-icons"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/1.0.4/leaflet.draw.js"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: {
50: '#eef2ff',
100: '#e0e7ff',
500: '#6366f1',
600: '#4f46e5',
700: '#4338ca',
900: '#312e81'
},
secondary: {
50: '#ecfdf5',
100: '#d1fae5',
500: '#10b981',
600: '#059669',
700: '#047857'
}
}
}
}
}
</script>
<link rel="stylesheet" href="style.css">
</head>
<body class="bg-gray-100 dark:bg-gray-900 h-screen overflow-hidden">
<script src="components/navbar.js"></script>
<script src="components/toolbox.js"></script>
<script src="components/device-preview.js"></script>
<script src="components/properties-panel.js"></script>
<geo-navbar></geo-navbar>
<div class="flex h-[calc(100vh-64px)]">
<!-- Toolbox Sidebar -->
<geo-toolbox></geo-toolbox>
<!-- Center Canvas -->
<div class="flex-1 flex flex-col relative bg-gray-200 dark:bg-gray-800">
<!-- Device Toolbar -->
<div class="bg-white dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600 p-3 flex justify-center gap-4 shadow-sm">
<button onclick="setDevice('mobile')" class="device-btn active p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" data-device="mobile">
<i data-feather="smartphone" class="w-5 h-5 text-gray-600 dark:text-gray-300"></i>
</button>
<button onclick="setDevice('tablet')" class="device-btn p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" data-device="tablet">
<i data-feather="tablet" class="w-5 h-5 text-gray-600 dark:text-gray-300"></i>
</button>
<button onclick="setDevice('desktop')" class="device-btn p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors" data-device="desktop">
<i data-feather="monitor" class="w-5 h-5 text-gray-600 dark:text-gray-300"></i>
</button>
<div class="w-px h-6 bg-gray-300 dark:bg-gray-500 mx-2"></div>
<button onclick="toggleTheme()" class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors">
<i data-feather="sun" class="w-5 h-5 text-gray-600 dark:text-gray-300 hidden dark:block"></i>
<i data-feather="moon" class="w-5 h-5 text-gray-600 dark:text-gray-300 block dark:hidden"></i>
</button>
<button onclick="exportForm()" class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-600 transition-colors text-primary-600">
<i data-feather="download" class="w-5 h-5"></i>
</button>
</div>
<!-- Canvas Area -->
<div class="flex-1 overflow-auto p-8 flex justify-center items-start" id="canvasArea">
<geo-device-preview id="devicePreview"></geo-device-preview>
</div>
</div>
<!-- Properties Panel -->
<geo-properties-panel></geo-properties-panel>
</div>
<script src="script.js"></script>
<script>
feather.replace();
// Initialize builder with real functionality
let currentForm = {
id: null,
name: '',
description: '',
fields: [],
theme: 'dark'
};
let selectedFieldIndex = null;
function initBuilder() {
const urlParams = new URLSearchParams(window.location.search);
const formId = urlParams.get('form');
if (!formId) {
window.location.href = 'index.html';
return;
}
// Load form data
const forms = JSON.parse(localStorage.getItem('geoforms_list') || '[]');
const form = forms.find(f => f.id === formId);
if (!form) {
window.location.href = 'index.html';
return;
}
currentForm = {
...form,
fields: JSON.parse(localStorage.getItem(`geoform_${formId}`) || '[]')
};
// Update device preview
const preview = document.getElementById('devicePreview');
if (preview) {
preview.setFormTitle(currentForm.name, currentForm.description || 'Preencha os dados abaixo');
currentForm.fields.forEach(field => preview.addField(field));
}
// Listen for field events
preview?.addEventListener('fieldSelected', (e) => {
selectedFieldIndex = currentForm.fields.findIndex(f => f.id === e.detail.fieldId);
updatePropertiesPanel(e.detail);
});
preview?.addEventListener('fieldUpdated', (e) => {
const index = currentForm.fields.findIndex(f => f.id === e.detail.field.id);
if (index !== -1) {
currentForm.fields[index][e.detail.property] = e.detail.value;
saveForm();
}
});
preview?.addEventListener('fieldDeleted', (e) => {
const index = currentForm.fields.findIndex(f => f.id === e.detail.field.id);
if (index !== -1) {
currentForm.fields.splice(index, 1);
saveForm();
// Refresh preview
preview.shadowRoot.getElementById('formContent').innerHTML = '';
if (currentForm.fields.length === 0) {
preview.shadowRoot.getElementById('formContent').innerHTML = \`
<div class="empty-state">
<svg class="empty-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<line x1="12" y1="8" x2="12" y2="16"/>
<line x1="8" y1="12" x2="16" y2="12"/>
</svg>
<p>Arraste ferramentas da caixa ao lado</p>
</div>
\`;
} else {
currentForm.fields.forEach(field => preview.addField(field));
}
}
});
}
function updatePropertiesPanel(fieldData) {
const panel = document.querySelector('geo-properties-panel');
if (panel) {
panel.showFieldProperties(fieldData);
}
}
function saveForm() {
localStorage.setItem(`geoform_${currentForm.id}`, JSON.stringify(currentForm.fields));
const forms = JSON.parse(localStorage.getItem('geoforms_list') || '[]');
const index = forms.findIndex(f => f.id === currentForm.id);
if (index !== -1) {
forms[index].fields = currentForm.fields;
forms[index].updatedAt = new Date().toISOString();
localStorage.setItem('geoforms_list', JSON.stringify(forms));
}
}
function setDevice(device) {
const preview = document.getElementById('devicePreview');
if (preview) {
preview.setAttribute('device-type', device);
}
document.querySelectorAll('.device-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.device === device);
});
}
function exportForm() {
const exportData = {
metadata: {
id: currentForm.id,
name: currentForm.name,
description: currentForm.description,
createdAt: currentForm.createdAt,
updatedAt: new Date().toISOString()
},
schema: currentForm.fields,
config: {
theme: currentForm.theme,
version: '2.0.0'
}
};
// Create comprehensive export package
const jsonContent = JSON.stringify(exportData, null, 2);
const htmlContent = generateStandaloneHTML(exportData);
// Create manifest with all files
const manifest = {
name: currentForm.name,
generatedAt: new Date().toISOString(),
files: {
'form-config.json': jsonContent,
'form-mobile.html': htmlContent,
'form-preview.html': generatePreviewHTML(exportData),
'README.txt': \`FormForge GeoStudio Export
=============================
Formulário: \${currentForm.name}
Gerado em: \${new Date().toLocaleString('pt-BR')}
ARQUIVOS:
- form-config.json: Configuração do formulário
- form-mobile.html: Versão mobile standalone
- form-preview.html: Preview do formulário
INSTRUÇÕES:
1. Abra form-mobile.html em um navegador mobile
2. Ou importe form-config.json no FormForge GeoStudio
\`
}
};
// Download as JSON package
const blob = new Blob([JSON.stringify(manifest, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = \`\${currentForm.name.replace(/\\s+/g, '_')}_FormForge_Package.json\`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
alert('📦 Pacote exportado com sucesso!\\n\\nO arquivo JSON contém:\\n✓ Configuração do formulário\\n✓ HTML mobile standalone\\n✓ Preview HTML\\n✓ Instruções de uso');
}
function generateStandaloneHTML(data) {
return \`<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>\${data.metadata.name}</title>
<link rel="manifest" href="data:application/json;base64,\${btoa(JSON.stringify({name: data.metadata.name, start_url: '.', display: 'standalone', background_color: '#4f46e5'}))}">
<style>
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 0;
background: #f3f4f6;
-webkit-font-smoothing: antialiased;
}
.header {
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
color: white;
padding: 1.25rem;
position: sticky;
top: 0;
z-index: 100;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.header h1 { margin: 0 0 0.25rem 0; font-size: 1.25rem; font-weight: 700; }
.header p { margin: 0; font-size: 0.875rem; opacity: 0.9; }
.form { padding: 1rem; max-width: 600px; margin: 0 auto; padding-bottom: 6rem; }
.field {
margin-bottom: 1rem;
background: white;
padding: 1rem;
border-radius: 12px;
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.field-label {
display: block;
font-size: 0.875rem;
font-weight: 600;
color: #374151;
margin-bottom: 0.5rem;
}
.field-required { color: #ef4444; margin-left: 0.25rem; }
.field-input {
width: 100%;
padding: 0.75rem;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 16px;
background: #f9fafb;
transition: all 0.2s;
}
.field-input:focus {
outline: none;
border-color: #4f46e5;
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.field-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E"); background-position: right 0.5rem center; background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem; }
.photo-upload {
border: 2px dashed #d1d5db;
border-radius: 8px;
padding: 2rem;
text-align: center;
color: #6b7280;
cursor: pointer;
transition: all 0.2s;
}
.photo-upload:active { background: #f3f4f6; border-color: #4f46e5; }
.map-container {
height: 200px;
border-radius: 8px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 0.875rem;
}
.signature-pad {
height: 120px;
border: 2px dashed #d1d5db;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: #9ca3af;
font-size: 0.875rem;
}
.submit-btn {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 1rem;
background: white;
border-top: 1px solid #e5e7eb;
max-width: 600px;
margin: 0 auto;
}
.submit-btn button {
width: 100%;
padding: 1rem;
background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
color: white;
border: none;
border-radius: 12px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
}
.submit-btn button:active { transform: translateY(1px); }
.textarea-field { min-height: 100px; resize: vertical; }
/* Success animation */
@keyframes successPulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.success-animation {
animation: successPulse 0.5s ease;
}
</style>
</head>
<body>
<div class="header">
<h1>${data.metadata.name}</h1>
${data.metadata.description ? `<p>${data.metadata.description}</p>` : ''}
</div>
<form class="form" id="geoForm" onsubmit="handleSubmit(event)">
${data.schema.map(field => {
const required = field.required ? '<span class="field-required">*</span>' : '';
const inputName = \`field_\${field.id}\`;
switch(field.type) {
case 'text':
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<input type="text" name="\${inputName}" class="field-input" placeholder="\${field.placeholder || ''}" \${field.required ? 'required' : ''}>
</div>\`;
case 'textarea':
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<textarea name="\${inputName}" class="field-input textarea-field" rows="4" placeholder="\${field.placeholder || ''}" \${field.required ? 'required' : ''}></textarea>
</div>\`;
case 'number':
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<input type="number" name="\${inputName}" class="field-input" \${field.required ? 'required' : ''}>
</div>\`;
case 'select':
const options = (field.options || 'Opção 1, Opção 2').split(',').map(o => o.trim());
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<select name="\${inputName}" class="field-input field-select" \${field.required ? 'required' : ''}>
<option value="">Selecione...</option>
\${options.map(o => \`<option value="\${o}">\${o}</option>\`).join('')}
</select>
</div>\`;
case 'date':
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<input type="date" name="\${inputName}" class="field-input" \${field.required ? 'required' : ''}>
</div>\`;
case 'photo':
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<div class="photo-upload" onclick="capturePhoto('\${inputName}')" id="photo_\${inputName}">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="margin: 0 auto 0.5rem;">
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"/>
<circle cx="8.5" cy="8.5" r="1.5"/>
<polyline points="21 15 16 10 5 21"/>
</svg>
<div>Toque para capturar foto</div>
<input type="file" name="\${inputName}" id="input_\${inputName}" accept="image/*" capture="environment" style="display: none;" \${field.required ? 'required' : ''}>
</div>
</div>\`;
case 'map':
const geoType = field.geometryType || 'point';
const geoLabel = geoType === 'point' ? '📍 Ponto' : geoType === 'line' ? '📏 Linha' : '⬡ Polígono';
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<div class="map-container" id="map_\${inputName}">
<div>
<div style="font-size: 2rem; margin-bottom: 0.5rem;">🗺️</div>
<div>Mapa - \${geoLabel}</div>
<div style="font-size: 0.75rem; margin-top: 0.5rem; opacity: 0.8;">
Toque para abrir mapa interativo
</div>
</div>
</div>
<input type="hidden" name="\${inputName}" id="input_\${inputName}" \${field.required ? 'required' : ''}>
</div>\`;
case 'signature':
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<div class="signature-pad" onclick="openSignature('\${inputName}')" id="sig_\${inputName}">
✍️ Toque para assinar
</div>
<input type="hidden" name="\${inputName}" id="input_\${inputName}" \${field.required ? 'required' : ''}>
</div>\`;
default:
return \`<div class="field">
<label class="field-label">\${field.label}\${required}</label>
<input type="text" name="\${inputName}" class="field-input" \${field.required ? 'required' : ''}>
</div>\`;
}
}).join('')}
<div class="submit-btn">
<button type="submit">
✅ Enviar Dados
</button>
</div>
</form>
<script>
// Photo capture
function capturePhoto(fieldName) {
const input = document.getElementById('input_' + fieldName);
const container = document.getElementById('photo_' + fieldName);
input.onchange = function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(evt) {
container.innerHTML = \`<img src="\${evt.target.result}" style="max-width: 100%; border-radius: 8px;">\`;
};
reader.readAsDataURL(file);
}
};
input.click();
}
// Map capture (simplified - would use actual map in production)
function openMap(fieldName, geometryType) {
// In production, this would open an interactive map
const coords = prompt('Digite as coordenadas (lat,lng):', '-23.5505,-46.6333');
if (coords) {
document.getElementById('input_' + fieldName).value = coords;
document.getElementById('map_' + fieldName).style.background = 'linear-gradient(135deg, #10b981 0%, #059669 100%)';
}
}
// Signature capture
function openSignature(fieldName) {
// In production, this would open a signature pad
const confirmed = confirm('Simular assinatura capturada?');
if (confirmed) {
document.getElementById('input_' + fieldName).value = 'signature_' + Date.now();
document.getElementById('sig_' + fieldName).innerHTML = '✅ Assinatura capturada';
document.getElementById('sig_' + fieldName).style.background = '#d1fae5';
document.getElementById('sig_' + fieldName).style.color = '#065f46';
}
}
// Form submission
function handleSubmit(e) {
e.preventDefault();
const formData = new FormData(e.target);
const data = Object.fromEntries(formData.entries());
// Show success animation
const btn = e.target.querySelector('button[type="submit"]');
btn.classList.add('success-animation');
btn.innerHTML = '✅ Enviado com sucesso!';
btn.style.background = 'linear-gradient(135deg, #10b981 0%, #059669 100%)';
console.log('Form data:', data);
setTimeout(() => {
alert('✅ Formulário enviado com sucesso!\\n\\nDados coletados:\\n' + JSON.stringify(data, null, 2));
btn.classList.remove('success-animation');
btn.innerHTML = '✅ Enviar Dados';
btn.style.background = '';
e.target.reset();
}, 500);
}
// Initialize map clicks
document.querySelectorAll('[id^="map_"]').forEach(map => {
const fieldName = map.id.replace('map_', '');
const field = ${JSON.stringify(data.schema)}.find(f => 'field_' + f.id === fieldName);
map.addEventListener('click', () => openMap(fieldName, field?.geometryType || 'point'));
});
<\/script>
</body>
</html>\`;
}
function generatePreviewHTML(data) {
return generateStandaloneHTML(data).replace('form-mobile.html', '#');
}
// Initialize on load
initBuilder();
</script>
</body>
</html>