-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_autoload_esm.html
More file actions
81 lines (70 loc) · 2.83 KB
/
example_autoload_esm.html
File metadata and controls
81 lines (70 loc) · 2.83 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Autoload Example (ESM) - 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-specific overrides - 80vh total for all content */
.example-header {
margin-bottom: 5px;
}
#editor {
height: calc(90vh - 100px); /* 80vh minus header space */
}
</style>
</head>
<body>
<div class="example-header">
<h1 class="example-title">SquibView Autoload Example (ESM)</h1>
<div class="example-version" id="version-display"></div>
<p class="example-description">
Simple editor setup with autoloading of fence handler libraries (mermaid, highlight.js, MathJax, Leaflet, Three.js) from CDN on demand.
</p>
</div>
<div class="editor-container">
<div id="editor"></div>
</div>
<script type="module">
// Import standard SquibView build - autoload is now built-in!
import SquibView from '../dist/squibview.esm.min.js';
// Initialize SquibView with autoloading enabled
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}`;
}
// Create SquibView instance with autoload enabled
const editor = new SquibView('#editor', {
initialView: 'split',
showControls: true,
titleShow: false, // Title is now in the HTML header
autoload_deps: { all: true } // Enable autoloading for all libraries
});
// Load sample content
const response = await fetch('./sample-content.md');
const content = await response.text();
editor.setContent(content, 'md');
// Make editor available globally for debugging
window.editor = editor;
// Autoload initialized - libraries will load silently as needed
} catch (error) {
console.error('Failed to initialize SquibView:', error);
document.getElementById('editor').innerHTML = `
<div style="padding: 20px; color: red;">
Failed to initialize: ${error.message}
</div>
`;
}
};
// Start initialization
init();
</script>
</body>
</html>