forked from djohnsen21/scaffolded_systems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkspace.html
More file actions
310 lines (275 loc) · 8.23 KB
/
workspace.html
File metadata and controls
310 lines (275 loc) · 8.23 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
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workspace – Scaffolded System</title>
<link rel="stylesheet" href="scaffoldedstyles.css">
<style>
.workspace-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: center;
padding: 60px 20px;
gap: 40px;
}
.input-section {
flex: 1;
max-width: 400px;
background: white;
padding: 30px;
border-radius: 16px;
box-shadow: 0 6px 16px rgba(0,0,0,0.1);
}
.input-section input[type="number"] {
font-size: 1.1rem;
padding: 12px;
width: 100%;
box-sizing: border-box;
margin-bottom: 10px;
}
.map-section {
flex: 2;
background: #f9f9f9;
padding: 30px;
border-radius: 16px;
box-shadow: 0 6px 16px rgba(0,0,0,0.1);
display: flex;
flex-direction: column;
align-items: center;
overflow: auto;
}
.map-layer {
display: flex;
gap: 20px;
flex-wrap: wrap;
justify-content: center;
align-items: center;
width: 100%;
margin: 30px 0;
flex-shrink: 0;
}
.map-node {
background: #64b5f6;
color: white;
padding: 16px 20px;
border-radius: 10px;
cursor: grab;
position: relative;
font-size: 1rem;
transition: transform 0.2s ease;
display: flex;
align-items: center;
gap: 10px;
}
.map-node:hover {
transform: scale(1.05);
}
.map-node.end-goal {
background: #35b313;
font-size: 1.3rem;
font-weight: bold;
padding: 20px 28px;
}
.delete-btn {
background: transparent;
border: none;
color: #e53935;
font-size: 1.4rem;
font-weight: bold;
cursor: pointer;
padding: 0 6px;
display: flex;
align-items: center;
justify-content: center;
}
.delete-btn:hover {
color: #ff7f7f;
}
.map-arrows {
font-size: 28px;
color: #00796b;
margin: 10px auto;
text-align: center;
width: 100%;
}
.add-below-btn {
background: #4caf50;
color: white;
border: none;
padding: 8px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.95rem;
margin-top: 6px;
}
.ai-feedback-inline {
margin-top: 20px;
text-align: center;
}
.ai-feedback-inline button,
.export-share-buttons button {
background-color: #00796b;
color: white;
padding: 12px 20px;
font-size: 1rem;
border: none;
border-radius: 8px;
cursor: pointer;
margin: 5px 0;
}
.ai-feedback-inline button:hover,
.export-share-buttons button:hover {
background-color: #004d40;
}
.export-share-buttons {
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<div id="nav-placeholder"></div>
<div class="workspace-container">
<div class="input-section">
<h2>Start Building</h2>
<label for="goal">End Goal:</label>
<input type="text" id="goal" placeholder="e.g. Community is food secure">
<button onclick="setGoal()">Set Goal</button>
<hr>
<h3>Add Precondition</h3>
<label for="target-layer">Layer #:</label>
<input type="number" id="target-layer" min="1" value="1">
<input type="text" id="precondition" placeholder="Enter a precondition">
<button onclick="addPrecondition()">Add</button>
<div class="ai-feedback-inline">
<p>Need help refining your logic?</p>
<button onclick="alert('AI feedback coming soon!')">Get AI Feedback</button>
</div>
<div class="export-share-buttons">
<button onclick="exportMapAsImage()">Export as Image</button>
<button onclick="shareMap()">Share</button>
</div>
</div>
<div class="map-section">
<div id="map"></div>
</div>
</div>
<script>
let mapData = JSON.parse(localStorage.getItem('mapData')) || [];
function saveMapData() {
localStorage.setItem('mapData', JSON.stringify(mapData));
}
function setGoal() {
const text = document.getElementById('goal').value.trim();
if (!text) return;
mapData = [[{ text, isGoal: true }]];
saveMapData();
renderMap();
}
function addPrecondition() {
const layer = parseInt(document.getElementById('target-layer').value);
const text = document.getElementById('precondition').value.trim();
if (!text || layer < 1) return;
while (mapData.length < layer + 1) mapData.push([]);
mapData[layer].push({ text, isGoal: false });
saveMapData();
renderMap();
}
function deleteNode(layer, index) {
mapData[layer].splice(index, 1);
if (layer > 0 && mapData[layer].length === 0) mapData.splice(layer, 1);
saveMapData();
renderMap();
}
function renderMap() {
const mapEl = document.getElementById('map');
mapEl.innerHTML = '';
mapData.forEach((layer, i) => {
const row = document.createElement('div');
row.className = 'map-layer';
layer.forEach((node, j) => {
const el = document.createElement('div');
el.className = 'map-node' + (node.isGoal ? ' end-goal' : '');
if (i !== 0) {
el.setAttribute('draggable', true);
el.ondragstart = (e) => {
e.dataTransfer.setData("text/plain", JSON.stringify({ i, j }));
};
}
const span = document.createElement('span');
span.textContent = node.text;
el.appendChild(span);
const delBtn = document.createElement('button');
delBtn.className = 'delete-btn';
delBtn.textContent = '×';
delBtn.onclick = () => deleteNode(i, j);
el.appendChild(delBtn);
row.appendChild(el);
});
if (i !== 0) {
row.ondragover = (e) => e.preventDefault();
row.ondrop = (e) => {
e.preventDefault();
const { i: fromLayer, j: fromIndex } = JSON.parse(e.dataTransfer.getData("text/plain"));
if (fromLayer === 0 || i === 0) return;
const movedNode = mapData[fromLayer][fromIndex];
mapData[fromLayer].splice(fromIndex, 1);
if (mapData[fromLayer].length === 0 && fromLayer !== 0) mapData.splice(fromLayer, 1);
mapData[i].push(movedNode);
saveMapData();
renderMap();
};
}
mapEl.appendChild(row);
if (i < mapData.length - 1) {
const arrow = document.createElement('div');
arrow.className = 'map-arrows';
arrow.textContent = '↓';
mapEl.appendChild(arrow);
}
});
}
function exportMapAsImage() {
const mapEl = document.getElementById("map");
const clone = mapEl.cloneNode(true);
const container = document.createElement('div');
container.style.position = 'fixed';
container.style.left = '-9999px';
container.style.top = '0';
container.style.width = mapEl.scrollWidth + 'px';
container.style.height = mapEl.scrollHeight + 'px';
container.appendChild(clone);
document.body.appendChild(container);
html2canvas(clone, {
useCORS: true,
width: mapEl.scrollWidth,
height: mapEl.scrollHeight,
windowWidth: mapEl.scrollWidth,
windowHeight: mapEl.scrollHeight
}).then(canvas => {
const link = document.createElement('a');
link.download = 'map.png';
link.href = canvas.toDataURL();
link.click();
document.body.removeChild(container);
});
}
function shareMap() {
const shareData = {
title: 'My Theory of Change Map',
text: 'Check out this map I made using Scaffolded System!',
url: window.location.href
};
if (navigator.share) {
navigator.share(shareData).catch(err => alert('Error sharing: ' + err));
} else {
alert('Sharing is not supported in this browser.');
}
}
window.onload = renderMap;
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"></script>
</body>
</html>