lightview 2.0.3 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 - 2026 Simon Y. Blackwell, AnyWhichWay LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/docs/about.html
CHANGED
|
@@ -82,10 +82,11 @@
|
|
|
82
82
|
</p>
|
|
83
83
|
|
|
84
84
|
<p>
|
|
85
|
-
The resulting Lightview 2.0 library is a replacement for an experiment I ran 4 years ago to create a
|
|
85
|
+
The resulting Lightview 2.0 library is a replacement for an experiment I ran 4 years ago to create a library
|
|
86
86
|
with
|
|
87
|
-
remote state storage and extended type declarations for state management.
|
|
88
|
-
Although
|
|
87
|
+
remote state storage and extended type declarations for state management.
|
|
88
|
+
Although Lightview 2.0 drops some of the features of Lightview v1.0 and is not syntax compatible, it brings
|
|
89
|
+
together
|
|
89
90
|
the features I craved without
|
|
90
91
|
locking me into a single paradigm. I hope you like it.
|
|
91
92
|
</p>
|
|
@@ -103,7 +104,7 @@
|
|
|
103
104
|
<div class="feature-card">
|
|
104
105
|
<h3 class="feature-title">🪶 Keep It Light</h3>
|
|
105
106
|
<p class="feature-description">
|
|
106
|
-
Life's too short for heavy frameworks. Although
|
|
107
|
+
Life's too short for heavy frameworks. Although Lightview is not tiny (core is 8K), I tried to keep
|
|
107
108
|
it lean and modular so your apps stay fast.
|
|
108
109
|
</p>
|
|
109
110
|
</div>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<title>Examplify Sandbox</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
height: 100vh;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
background: #f9fafb;
|
|
16
|
+
color: #6b7280;
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
user-select: none;
|
|
19
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
20
|
+
transition: color 0.2s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
body:hover {
|
|
24
|
+
color: #374151;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.content {
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: 0.5rem;
|
|
31
|
+
font-size: 0.875rem;
|
|
32
|
+
font-weight: 500;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#placeholder {
|
|
36
|
+
display: flex;
|
|
37
|
+
align-items: center;
|
|
38
|
+
justify-content: center;
|
|
39
|
+
width: 100%;
|
|
40
|
+
height: 100%;
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
43
|
+
</head>
|
|
44
|
+
|
|
45
|
+
<body>
|
|
46
|
+
<div id="placeholder">
|
|
47
|
+
<div class="content">
|
|
48
|
+
<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor">
|
|
49
|
+
<path d="M8 5v14l11-7z" />
|
|
50
|
+
</svg>
|
|
51
|
+
<span>Click to run</span>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
<script>
|
|
55
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
56
|
+
const iframeId = urlParams.get('id');
|
|
57
|
+
|
|
58
|
+
document.getElementById('placeholder').onclick = () => {
|
|
59
|
+
parent.postMessage({ type: 'examplify-run-click', id: iframeId }, '*');
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
window.addEventListener('message', (event) => {
|
|
63
|
+
if (event.data && event.data.type === 'examplify-load-content') {
|
|
64
|
+
// Replace the entire document content
|
|
65
|
+
document.open();
|
|
66
|
+
document.write(event.data.content);
|
|
67
|
+
document.close();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
// Signal to parent that we are ready to receive content
|
|
71
|
+
parent.postMessage({ type: 'examplify-sandbox-ready', id: iframeId }, '*');
|
|
72
|
+
</script>
|
|
73
|
+
</body>
|
|
74
|
+
|
|
75
|
+
</html>
|
|
@@ -3,13 +3,15 @@ var examplifyIdCounter = window.examplifyIdCounter || 0;
|
|
|
3
3
|
window.examplifyIdCounter = examplifyIdCounter;
|
|
4
4
|
|
|
5
5
|
function examplify(target, options = {}) {
|
|
6
|
-
const { scripts, styles, modules, html, at, location = 'beforeBegin', type, height, minHeight = 100, maxHeight = Infinity, allowSameOrigin = false, language = 'js', autoRun = false } = options;
|
|
6
|
+
const { scripts, styles, modules, html, at, location = 'beforeBegin', type, height, minHeight = 100, maxHeight = Infinity, allowSameOrigin = false, useOrigin = null, language = 'js', autoRun = false } = options;
|
|
7
7
|
const originalContent = target.textContent;
|
|
8
8
|
const autoResize = !height; // Auto-resize if no explicit height is provided
|
|
9
9
|
const iframeId = `examplify-${++examplifyIdCounter}`;
|
|
10
10
|
|
|
11
11
|
// State
|
|
12
12
|
let isRunning = false;
|
|
13
|
+
let sandboxReady = false;
|
|
14
|
+
let pendingContent = null;
|
|
13
15
|
|
|
14
16
|
// 2. Create controls above the target
|
|
15
17
|
const controls = document.createElement('div');
|
|
@@ -47,7 +49,9 @@ function examplify(target, options = {}) {
|
|
|
47
49
|
iframe.style.background = '#f9fafb'; // Light gray placeholder
|
|
48
50
|
iframe.style.border = '1px solid #e5e7eb';
|
|
49
51
|
iframe.style.transition = 'opacity 0.2s ease-in, height 0.2s ease-out';
|
|
50
|
-
|
|
52
|
+
const sandboxFlags = ['allow-scripts'];
|
|
53
|
+
if (allowSameOrigin) sandboxFlags.push('allow-same-origin');
|
|
54
|
+
iframe.sandbox = sandboxFlags.join(' ');
|
|
51
55
|
|
|
52
56
|
if (height) iframe.style.height = height;
|
|
53
57
|
if (minHeight) iframe.style.minHeight = typeof minHeight === 'number' ? `${minHeight}px` : minHeight;
|
|
@@ -58,6 +62,11 @@ function examplify(target, options = {}) {
|
|
|
58
62
|
iframe.style.height = '100px';
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
// If using an external origin, set src immediately to avoid sandbox warnings
|
|
66
|
+
if (useOrigin) {
|
|
67
|
+
iframe.src = useOrigin + '/docs/assets/js/examplify-sandbox.html?id=' + iframeId;
|
|
68
|
+
}
|
|
69
|
+
|
|
61
70
|
// Insert elements
|
|
62
71
|
const insertionPoint = (at || target);
|
|
63
72
|
insertionPoint.insertAdjacentElement(location, iframe);
|
|
@@ -288,16 +297,29 @@ function examplify(target, options = {}) {
|
|
|
288
297
|
function run() {
|
|
289
298
|
const content = getIframeContent(target.textContent);
|
|
290
299
|
iframe.style.background = '#fff';
|
|
291
|
-
|
|
300
|
+
|
|
301
|
+
if (useOrigin) {
|
|
302
|
+
if (sandboxReady) {
|
|
303
|
+
iframe.contentWindow.postMessage({ type: 'examplify-load-content', content: content, id: iframeId }, '*');
|
|
304
|
+
} else {
|
|
305
|
+
pendingContent = content;
|
|
306
|
+
// iframe.src is already set in the initialization phase
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
iframe.srcdoc = content;
|
|
310
|
+
}
|
|
292
311
|
isRunning = true;
|
|
293
312
|
}
|
|
294
313
|
|
|
295
314
|
// Initialize: auto-run or show placeholder
|
|
296
315
|
if (autoRun) {
|
|
297
316
|
run();
|
|
298
|
-
} else {
|
|
317
|
+
} else if (!useOrigin) {
|
|
318
|
+
// Only use srcdoc for local placeholders when not using a separate origin
|
|
299
319
|
iframe.srcdoc = getPlaceholderContent();
|
|
300
320
|
}
|
|
321
|
+
// Note: if useOrigin is set, the sandbox page itself will handle being blank or showing placeholder
|
|
322
|
+
// until we post the content to it.
|
|
301
323
|
|
|
302
324
|
// Event Listeners
|
|
303
325
|
const runBtn = controls.querySelector('.examplify-run');
|
|
@@ -358,6 +380,14 @@ function examplify(target, options = {}) {
|
|
|
358
380
|
if (event.data.type === 'examplify-run-click') {
|
|
359
381
|
run();
|
|
360
382
|
}
|
|
383
|
+
|
|
384
|
+
if (event.data.type === 'examplify-sandbox-ready' && useOrigin) {
|
|
385
|
+
sandboxReady = true;
|
|
386
|
+
if (pendingContent) {
|
|
387
|
+
iframe.contentWindow.postMessage({ type: 'examplify-load-content', content: pendingContent, id: iframeId }, '*');
|
|
388
|
+
pendingContent = null;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
361
391
|
});
|
|
362
392
|
|
|
363
393
|
return { controls, iframe, target, run };
|
|
@@ -334,7 +334,7 @@ $('#app').content(App);`,
|
|
|
334
334
|
},
|
|
335
335
|
4: {
|
|
336
336
|
options: {
|
|
337
|
-
allowSameOrigin: true,
|
|
337
|
+
//allowSameOrigin: true,
|
|
338
338
|
autoRun: true
|
|
339
339
|
},
|
|
340
340
|
code: `// STEP 4: HYPERMEDIA + OBJECT DOM SYNTAX (requires lightview-x)
|
|
@@ -639,6 +639,12 @@ $('#app').content(App);`,
|
|
|
639
639
|
conceptsContainer.appendChild(conceptsEl);
|
|
640
640
|
|
|
641
641
|
// 4. Initialize Examplify
|
|
642
|
+
const useOrigin = (data.options?.allowSameOrigin && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'))
|
|
643
|
+
? (window.location.hostname === 'localhost'
|
|
644
|
+
? window.location.origin.replace('localhost', '127.0.0.1')
|
|
645
|
+
: window.location.origin.replace('127.0.0.1', 'localhost'))
|
|
646
|
+
: (data.options?.allowSameOrigin ? 'https://sandbox.lightview.dev' : null);
|
|
647
|
+
|
|
642
648
|
// Check if step uses modules (looking for import statement)
|
|
643
649
|
const isModule = data.code.includes('import ');
|
|
644
650
|
|
|
@@ -647,6 +653,7 @@ $('#app').content(App);`,
|
|
|
647
653
|
html: '<div id="app" style="padding: 1rem;"></div>',
|
|
648
654
|
location: 'afterEnd',
|
|
649
655
|
type: isModule ? 'module' : 'text/javascript',
|
|
656
|
+
useOrigin,
|
|
650
657
|
...data.options || {}
|
|
651
658
|
});
|
|
652
659
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightview",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "A lightweight reactive UI library with features of Bau, Juris, and HTMX",
|
|
5
5
|
"main": "lightview.js",
|
|
6
6
|
"directories": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
16
|
},
|
|
17
17
|
"keywords": [],
|
|
18
|
-
"author": "",
|
|
18
|
+
"author": "Simon Y. Blackwell, AnyWhichWay LLC",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "commonjs",
|
|
21
21
|
"devDependencies": {
|