-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbpmn.html
More file actions
299 lines (266 loc) · 13.2 KB
/
bpmn.html
File metadata and controls
299 lines (266 loc) · 13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BPMN Editor Pro</title>
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- BPMN-js CSS -->
<link rel="stylesheet" href="https://unpkg.com/bpmn-js@17.11.1/dist/assets/diagram-js.css">
<link rel="stylesheet" href="https://unpkg.com/bpmn-js@17.11.1/dist/assets/bpmn-font/css/bpmn-embedded.css">
<!-- Lucide Icons -->
<script src="https://unpkg.com/lucide@latest"></script>
<style>
body, html { height: 100%; margin: 0; overflow: hidden; }
.bjs-powered-by { display: none !important; }
/* Customização da Paleta */
.djs-palette {
top: 20px !important;
left: 20px !important;
border-radius: 8px !important;
box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
border: 1px solid #e2e8f0 !important;
background-color: rgba(255, 255, 255, 0.95) !important;
}
#canvas {
height: 100%;
width: 100%;
background-color: white;
}
.sidebar-transition {
transition: width 0.3s ease-in-out;
}
/* Cor de destaque para edição direta */
.djs-direct-editing-parent {
border: 2px solid #6366f1 !important;
border-radius: 4px !important;
}
</style>
</head>
<body class="bg-gray-50 text-slate-800 flex flex-col h-screen font-sans">
<!-- Header / Toolbar -->
<header class="flex items-center justify-between px-6 py-3 bg-white border-b border-gray-200 shadow-sm z-30">
<div class="flex items-center gap-4">
<div class="bg-indigo-600 p-2 rounded-lg">
<i data-lucide="settings" class="text-white w-5 h-5"></i>
</div>
<input
id="fileNameInput"
type="text"
value="processo-novo.bpmn"
class="text-lg font-semibold bg-transparent border-none focus:ring-2 focus:ring-indigo-200 rounded px-2 transition-all outline-none text-slate-700"
/>
</div>
<div class="flex items-center gap-2">
<label class="flex items-center gap-2 px-4 py-2 bg-white border border-gray-300 rounded-md hover:bg-gray-50 cursor-pointer transition-colors text-sm font-medium">
<i data-lucide="upload" class="w-4 h-4"></i>
<span>Abrir</span>
<input id="importInput" type="file" class="hidden" accept=".bpmn, .xml" />
</label>
<div class="h-6 w-[1px] bg-gray-300 mx-2"></div>
<button
id="downloadSvgBtn"
class="flex items-center gap-2 px-4 py-2 bg-white border border-gray-300 rounded-md hover:bg-gray-50 transition-colors text-sm font-medium"
>
<i data-lucide="image" class="w-4 h-4"></i>
<span>SVG</span>
</button>
<button
id="downloadXmlBtn"
class="flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition-colors text-sm font-medium shadow-sm"
>
<i data-lucide="download" class="w-4 h-4"></i>
<span>Exportar BPMN</span>
</button>
</div>
</header>
<main class="flex flex-1 relative overflow-hidden">
<!-- Sidebar -->
<div id="sidebar" class="sidebar-transition w-64 border-r border-gray-200 bg-white z-20 flex flex-col">
<div class="flex flex-col h-full overflow-hidden">
<div class="p-4 border-b border-gray-100 flex justify-between items-center bg-gray-50">
<span class="font-bold text-xs uppercase tracking-wider text-slate-500">Propriedades</span>
<button id="closeSidebarBtn" class="hover:text-red-500 transition-colors">
<i data-lucide="x" class="w-4 h-4"></i>
</button>
</div>
<div class="flex-1 p-4 overflow-y-auto space-y-4">
<div class="space-y-1">
<label class="text-xs font-medium text-slate-400">ID do Elemento</label>
<div id="elementId" class="p-2 bg-gray-100 rounded text-sm text-slate-600 font-mono">Process_1</div>
</div>
<div class="space-y-1">
<label class="text-xs font-medium text-slate-400">Nome do Processo</label>
<input type="text" class="w-full p-2 border border-gray-200 rounded text-sm focus:ring-2 focus:ring-indigo-100 outline-none" placeholder="Ex: Contratação" />
</div>
<div class="pt-4">
<div class="text-xs font-semibold text-indigo-600 mb-2">Dica de Uso</div>
<p class="text-xs text-slate-500 leading-relaxed">
Use a paleta à esquerda para adicionar elementos. Clique duas vezes em um elemento para editá-lo. Arraste as conexões para ligar tarefas.
</p>
</div>
</div>
<div class="p-4 border-t border-gray-100 italic text-[10px] text-slate-400 text-center">
Editor Pro v1.0.0 (HTML Version)
</div>
</div>
</div>
<!-- Toggle Sidebar Button -->
<button
id="openSidebarBtn"
class="hidden absolute left-0 top-1/2 -translate-y-1/2 bg-white border border-l-0 border-gray-300 p-1 rounded-r-md z-30 shadow-md hover:bg-indigo-50 transition-all"
>
<i data-lucide="chevron-right" class="w-4 h-4 text-indigo-600"></i>
</button>
<!-- Canvas Area -->
<div class="flex-1 bg-white relative">
<div id="canvas"></div>
<!-- Floating Controls -->
<div class="absolute bottom-6 right-6 flex flex-col gap-2 z-10">
<div class="flex flex-col bg-white rounded-lg shadow-xl border border-gray-200 overflow-hidden">
<button id="zoomIn" title="Aproximar" class="p-3 hover:bg-gray-100 border-b border-gray-100">
<i data-lucide="plus" class="w-5 h-5"></i>
</button>
<button id="zoomOut" title="Afastar" class="p-3 hover:bg-gray-100 border-b border-gray-100">
<i data-lucide="minus" class="w-5 h-5"></i>
</button>
<button id="zoomReset" title="Ajustar à tela" class="p-3 hover:bg-gray-100">
<i data-lucide="maximize" class="w-5 h-5"></i>
</button>
</div>
<button
id="undoBtn"
title="Desfazer"
class="bg-white p-3 rounded-lg shadow-xl border border-gray-200 hover:bg-gray-100 active:scale-95 transition-transform"
>
<i data-lucide="rotate-ccw" class="w-5 h-5"></i>
</button>
</div>
<!-- Loading Overlay -->
<div id="loadingOverlay" class="absolute inset-0 flex items-center justify-center bg-white z-40">
<div class="flex flex-col items-center gap-3">
<div class="w-10 h-10 border-4 border-indigo-600 border-t-transparent rounded-full animate-spin"></div>
<span class="text-slate-600 font-medium tracking-wide">Iniciando Engine BPMN...</span>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="px-6 py-2 bg-gray-50 border-t border-gray-200 text-[11px] text-slate-500 flex justify-between items-center z-30">
<div>Modelador Profissional baseado em Padrões OMG.</div>
<div class="flex gap-4">
<span><b>Atalhos:</b> Espaço + Arrastar (Pan), Ctrl + Z (Desfazer), Scroll (Zoom)</span>
</div>
</footer>
<!-- Scripts -->
<script src="https://unpkg.com/bpmn-js@17.11.1/dist/bpmn-modeler.development.js"></script>
<script>
// Inicializar ícones
lucide.createIcons();
// Diagrama Inicial
const initialDiagram = `<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:startEvent id="StartEvent_1" name="Início" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>`;
// Instanciar Modeler
const bpmnModeler = new BpmnJS({
container: '#canvas',
keyboard: {
bindTo: window
}
});
// Carregar Diagrama
async function openDiagram(xml) {
try {
await bpmnModeler.importXML(xml);
document.getElementById('loadingOverlay').classList.add('hidden');
bpmnModeler.get('canvas').zoom('fit-viewport');
} catch (err) {
console.error('Erro ao carregar BPMN:', err);
alert('Erro ao carregar o diagrama. Verifique o formato do arquivo.');
}
}
// Exportar XML
async function exportDiagram() {
try {
const { xml } = await bpmnModeler.saveXML({ format: true });
const fileName = document.getElementById('fileNameInput').value;
downloadFile(xml, fileName.endsWith('.bpmn') ? fileName : fileName + '.bpmn', 'text/bpmn');
} catch (err) {
console.error('Erro ao exportar:', err);
}
}
// Exportar SVG
async function exportSVG() {
try {
const { svg } = await bpmnModeler.saveSVG();
const fileName = document.getElementById('fileNameInput').value.replace('.bpmn', '');
downloadFile(svg, fileName + '.svg', 'image/svg+xml');
} catch (err) {
console.error('Erro ao exportar SVG:', err);
}
}
// Função Auxiliar de Download
function downloadFile(content, fileName, contentType) {
const a = document.createElement("a");
const file = new Blob([content], { type: contentType });
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
URL.revokeObjectURL(a.href);
}
// --- Event Listeners ---
document.getElementById('downloadXmlBtn').addEventListener('click', exportDiagram);
document.getElementById('downloadSvgBtn').addEventListener('click', exportSVG);
document.getElementById('importInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
document.getElementById('fileNameInput').value = file.name;
const reader = new FileReader();
reader.onload = (event) => openDiagram(event.target.result);
reader.readAsText(file);
});
// Controles de Canvas
document.getElementById('zoomIn').addEventListener('click', () => bpmnModeler.get('zoomScroll').stepZoom(1));
document.getElementById('zoomOut').addEventListener('click', () => bpmnModeler.get('zoomScroll').stepZoom(-1));
document.getElementById('zoomReset').addEventListener('click', () => bpmnModeler.get('canvas').zoom('fit-viewport'));
document.getElementById('undoBtn').addEventListener('click', () => bpmnModeler.get('commandStack').undo());
// Controle de Sidebar
const sidebar = document.getElementById('sidebar');
const closeBtn = document.getElementById('closeSidebarBtn');
const openBtn = document.getElementById('openSidebarBtn');
closeBtn.addEventListener('click', () => {
sidebar.classList.add('w-0');
sidebar.classList.remove('w-64');
openBtn.classList.remove('hidden');
});
openBtn.addEventListener('click', () => {
sidebar.classList.remove('w-0');
sidebar.classList.add('w-64');
openBtn.classList.add('hidden');
});
// Escutar seleção de elementos para atualizar painel (Mock)
bpmnModeler.on('selection.changed', (e) => {
const selection = e.newSelection;
const idDisplay = document.getElementById('elementId');
if (selection.length) {
idDisplay.innerText = selection[0].id;
} else {
idDisplay.innerText = 'Process_1';
}
});
// Iniciar
window.onload = () => openDiagram(initialDiagram);
</script>
</body>
</html>