-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
140 lines (125 loc) · 5.03 KB
/
index.html
File metadata and controls
140 lines (125 loc) · 5.03 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>modeld</title>
<link rel="icon" href="static/modeld.png">
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/js-yaml@4.1.0/dist/js-yaml.min.js"></script>
<script src="/node_modules/ace-builds/src-min-noconflict/ace.js"></script>
</head>
<body>
<div id="drag-overlay"></div>
<div id="editor-pane">
<div id="editor-topbar">
<span id="save-status">loading...</span>
<div id="editor-actions">
<button id="btn-reload"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"/><path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/></svg>reload</button>
<button id="btn-new"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>new</button>
</div>
</div>
<div id="editor"></div>
</div>
<div id="divider" tabindex="-1"></div>
<iframe frameborder="0" id="drawio" src="/drawio/src/main/webapp/index.html?test=1"></iframe>
<script src="dist/app.bundle.js"></script>
<script>
// Coordinate model.yaml fetch with draw.io ready so both are in place before initial sync.
// Whichever arrives second triggers the original onDrawioReady.
const _origOnDioReady = window.onDrawioReady;
let _modelYamlReady = false;
let _drawioReadyPending = false;
window.onDrawioReady = function () {
if (_modelYamlReady) {
_origOnDioReady();
} else {
_drawioReadyPending = true;
}
};
function loadModel(yamlText) {
document.editor.setValue(yamlText, -1);
_modelYamlReady = true;
if (_drawioReadyPending) {
window.onDrawioReady = _origOnDioReady;
_origOnDioReady();
} else {
window.onDrawioReady = _origOnDioReady;
}
window.__onModelLoaded?.();
}
const hash = window.location.hash.slice(1);
if (hash) {
try {
loadModel(decodeURIComponent(escape(atob(hash))));
} catch(e) {
fetch('/model.yaml').then(r => r.text()).then(loadModel);
}
} else {
fetch('/model.yaml').then(r => r.text()).then(loadModel);
}
</script>
<script>
// Session ID + save status
const SESSION_ID = Math.random().toString(36).slice(2, 8);
const saveStatus = document.getElementById('save-status');
let saveTimer = null;
function setSaving() {
saveStatus.textContent = 'saving to ' + SESSION_ID + '.yml';
saveStatus.className = 'saving';
clearTimeout(saveTimer);
saveTimer = setTimeout(() => {
saveStatus.textContent = 'saved to ' + SESSION_ID + '.yml';
saveStatus.className = 'saved';
}, 600);
}
window.__onModelLoaded = function() {
saveStatus.textContent = 'saved to ' + SESSION_ID + '.yml';
saveStatus.className = 'saved';
};
// Wait for editor to be ready then attach change listener
function watchEditor() {
if (!document.editor) { setTimeout(watchEditor, 100); return; }
document.editor.getSession().on('change', function() {
if (document.editor.lockEvents === false &&
document.activeElement.className === 'ace_text-input') {
setSaving();
}
});
}
watchEditor();
document.getElementById('btn-reload').addEventListener('click', function() {
window.reloadDiagram();
});
const BLANK_MODEL = 'nodes:\n canvas:\n type: boundary\n meta:\n pos: 0,0\n size: 500,500\n';
document.getElementById('btn-new').addEventListener('click', function() {
window.reloadDiagram(BLANK_MODEL);
history.replaceState(null, '', window.location.pathname);
saveStatus.textContent = 'saved to ' + SESSION_ID + '.yml';
saveStatus.className = 'saved';
});
</script>
<script>
const divider = document.getElementById('divider')
const editorPane = document.getElementById('editor-pane')
const overlay = document.getElementById('drag-overlay')
divider.addEventListener('mousedown', function (e) {
divider.classList.add('dragging')
overlay.style.display = 'block'
function onMove(e) {
const pct = (e.clientX / window.innerWidth) * 100
editorPane.style.width = Math.min(80, Math.max(5, pct)) + '%'
document.editor.resize()
}
function onUp() {
divider.classList.remove('dragging')
overlay.style.display = 'none'
document.removeEventListener('mousemove', onMove)
document.removeEventListener('mouseup', onUp)
}
document.addEventListener('mousemove', onMove)
document.addEventListener('mouseup', onUp)
e.preventDefault()
})
</script>
</body>
</html>