-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_multi_editor.html
More file actions
307 lines (258 loc) · 8.31 KB
/
example_multi_editor.html
File metadata and controls
307 lines (258 loc) · 8.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Multi-Editor Example with Autoload - SquibView</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'><circle cx='16' cy='16' r='14' fill='%23f57c00' stroke='%23000' stroke-width='1'/><path d='M2 16h28M16 2a14 14 0 0114 14 14 14 0 01-14 14 14 14 0 01-14-14A14 14 0 0116 2zm0 0v28M9 16a7 7 0 0014 0 7 7 0 00-14 0z' fill='none' stroke='%23000' stroke-width='1'/></svg>">
<!-- SquibView CSS -->
<link rel="stylesheet" href="../dist/squibview.min.css">
<!-- Base example styles -->
<link rel="stylesheet" href="examples.css">
<style>
/* Page layout for multiple editors */
.editors-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
margin: 1rem;
height: calc(100vh - 200px);
}
.editor-box {
border: 1px solid #dee2e6;
border-radius: 4px;
overflow: hidden;
display: flex;
flex-direction: column;
}
.editor-title {
background: #f8f9fa;
padding: 0.5rem 1rem;
border-bottom: 1px solid #dee2e6;
font-weight: 600;
font-size: 0.9rem;
color: #495057;
}
.editor-wrapper {
flex: 1;
overflow: hidden;
}
#editor1, #editor2, #editor3, #editor4 {
height: 100%;
}
.headless-output {
padding: 1rem;
background: #f8f9fa;
border: 1px solid #dee2e6;
border-radius: 4px;
margin: 1rem;
font-family: monospace;
white-space: pre-wrap;
max-height: 150px;
overflow-y: auto;
}
@media (max-width: 768px) {
.editors-container {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="example-header">
<h1 class="example-title">Multiple Editors with Autoload</h1>
<div class="example-version" id="version-display"></div>
<p class="example-description">
Four SquibView instances on the same page with different configurations. All using autoload - libraries are loaded once and shared between all editors.
</p>
</div>
<div class="editors-container">
<!-- Editor 1: Source View Only -->
<div class="editor-box">
<div class="editor-title">Editor 1: Source View (Markdown editing)</div>
<div class="editor-wrapper">
<div id="editor1"></div>
</div>
</div>
<!-- Editor 2: Split View -->
<div class="editor-box">
<div class="editor-title">Editor 2: Split View (Live preview)</div>
<div class="editor-wrapper">
<div id="editor2"></div>
</div>
</div>
<!-- Editor 3: Rendered View Only -->
<div class="editor-box">
<div class="editor-title">Editor 3: Rendered View (Preview only)</div>
<div class="editor-wrapper">
<div id="editor3"></div>
</div>
</div>
<!-- Editor 4: Different Content (Math & Diagrams) -->
<div class="editor-box">
<div class="editor-title">Editor 4: Math & Diagrams Focus</div>
<div class="editor-wrapper">
<div id="editor4"></div>
</div>
</div>
</div>
<!-- Headless Editor Output -->
<div style="margin: 1rem;">
<div class="editor-title">Headless Editor (No UI - Processing only)</div>
<div class="headless-output" id="headless-output">
Headless editor output will appear here...
</div>
</div>
<script type="module">
import SquibView from '../dist/squibview.esm.min.js';
// Sample content for different editors
const codeContent = `# Code Examples
Here's some JavaScript code:
\`\`\`javascript
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
console.log(fibonacci(10));
\`\`\`
And some Python:
\`\`\`python
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
\`\`\`
`;
const mathDiagramContent = `# Math & Diagrams
## Mathematical Equations
Einstein's famous equation:
\`\`\`math
E = mc^2
\`\`\`
Gaussian integral:
\`\`\`math
\\int_{-\\infty}^{\\infty} e^{-x^2} dx = \\sqrt{\\pi}
\`\`\`
## Mermaid Diagram
\`\`\`mermaid
graph TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Great!]
B -->|No| D[Debug]
D --> A
\`\`\`
## Maxwell's Equation
\`\`\`math
\\nabla \\times \\vec{B} = \\mu_0 \\vec{J} + \\mu_0 \\epsilon_0 \\frac{\\partial \\vec{E}}{\\partial t}
\`\`\`
`;
const init = async () => {
try {
// Set version display from the library
if (SquibView.version && SquibView.version.version) {
document.getElementById("version-display").textContent = `Version ${SquibView.version.version}`;
}
} catch (error) {
console.error('Failed to set version:', error);
}
try {
// Load main sample content
let sampleContent;
try {
const response = await fetch('./sample-content.md');
sampleContent = await response.text();
} catch {
sampleContent = '# Sample Content\n\nEdit this markdown...';
}
// Editor 1: Source view only
const editor1 = new SquibView('#editor1', {
initialView: 'src',
showControls: true,
titleShow: false,
autoload_deps: { all: true } // Enable autoload for all
});
editor1.setContent(codeContent, 'md');
// Editor 2: Split view (default)
const editor2 = new SquibView('#editor2', {
initialView: 'split',
showControls: true,
titleShow: false,
autoload_deps: { all: true }
});
editor2.setContent(sampleContent, 'md');
// Editor 3: Rendered view only
const editor3 = new SquibView('#editor3', {
initialView: 'html',
showControls: true,
titleShow: false,
autoload_deps: { all: true }
});
editor3.setContent(sampleContent, 'md');
// Editor 4: Math and diagrams focus
const editor4 = new SquibView('#editor4', {
initialView: 'split',
showControls: true,
titleShow: false,
autoload_deps: {
// Custom config - only load what we need
mermaid: 'ondemand',
mathjax: 'ondemand',
hljs: false, // Don't need syntax highlighting
leaflet: false, // Don't need maps
three: false // Don't need 3D
}
});
editor4.setContent(mathDiagramContent, 'md');
// Headless editor - no DOM element, just processing
// Create a temporary hidden div
const hiddenDiv = document.createElement('div');
hiddenDiv.style.display = 'none';
document.body.appendChild(hiddenDiv);
const headlessEditor = new SquibView(hiddenDiv, {
showControls: false,
titleShow: false,
autoload_deps: { all: true }
});
// Process some markdown and get the HTML
const testMarkdown = `# Headless Processing
This editor has no UI. It's just processing markdown to HTML.
- Item 1
- Item 2
- **Bold text**
- *Italic text*
\`\`\`json
{
"headless": true,
"visible": false
}
\`\`\`
`;
headlessEditor.setContent(testMarkdown, 'md');
// Get the rendered HTML after a short delay to ensure rendering
setTimeout(() => {
const renderedHTML = headlessEditor.getHTMLSource();
document.getElementById('headless-output').innerHTML =
'Headless editor processed HTML:\n\n' +
renderedHTML.replace(/</g, '<').replace(/>/g, '>');
}, 100);
// Make editors available globally for debugging
window.editors = { editor1, editor2, editor3, editor4, headlessEditor };
console.log('All editors initialized successfully with autoload enabled');
console.log('Libraries will be loaded once and shared between all editors');
} catch (error) {
console.error('Failed to initialize editors:', error);
}
};
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
</script>
</body>
</html>