lightview 1.8.2 → 2.0.1
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/.codacy/cli.sh +149 -0
- package/.codacy/codacy.yaml +15 -0
- package/.github/instructions/codacy.instructions.md +72 -0
- package/.wranglerignore +21 -0
- package/README.md +1330 -19
- package/_headers +4 -0
- package/build.js +70 -0
- package/components/actions/button.js +151 -0
- package/components/actions/dropdown.js +120 -0
- package/components/actions/modal.js +146 -0
- package/components/actions/swap.js +118 -0
- package/components/daisyui.js +288 -0
- package/components/data-display/accordion.js +128 -0
- package/components/data-display/alert.js +112 -0
- package/components/data-display/avatar.js +170 -0
- package/components/data-display/badge.js +82 -0
- package/components/data-display/card.js +151 -0
- package/components/data-display/carousel.js +94 -0
- package/components/data-display/chart.js +220 -0
- package/components/data-display/chat.js +128 -0
- package/components/data-display/collapse.js +103 -0
- package/components/data-display/countdown.js +69 -0
- package/components/data-display/diff.js +111 -0
- package/components/data-display/kbd.js +65 -0
- package/components/data-display/loading.js +75 -0
- package/components/data-display/progress.js +79 -0
- package/components/data-display/radial-progress.js +88 -0
- package/components/data-display/skeleton.js +66 -0
- package/components/data-display/stats.js +159 -0
- package/components/data-display/table.js +146 -0
- package/components/data-display/timeline.js +146 -0
- package/components/data-display/toast.js +72 -0
- package/components/data-display/tooltip.js +74 -0
- package/components/data-input/checkbox.js +253 -0
- package/components/data-input/file-input.js +224 -0
- package/components/data-input/input.js +264 -0
- package/components/data-input/radio.js +338 -0
- package/components/data-input/range.js +204 -0
- package/components/data-input/rating.js +219 -0
- package/components/data-input/select.js +287 -0
- package/components/data-input/textarea.js +287 -0
- package/components/data-input/toggle.js +201 -0
- package/components/index.js +137 -0
- package/components/layout/divider.js +72 -0
- package/components/layout/drawer.js +142 -0
- package/components/layout/footer.js +100 -0
- package/components/layout/hero.js +109 -0
- package/components/layout/indicator.js +90 -0
- package/components/layout/join.js +78 -0
- package/components/layout/navbar.js +110 -0
- package/components/navigation/breadcrumbs.js +91 -0
- package/components/navigation/dock.js +103 -0
- package/components/navigation/menu.js +126 -0
- package/components/navigation/pagination.js +105 -0
- package/components/navigation/steps.js +89 -0
- package/components/navigation/tabs.css +177 -0
- package/components/navigation/tabs.js +123 -0
- package/components/theme/theme-switch.css +65 -0
- package/components/theme/theme-switch.js +177 -0
- package/docs/about.html +164 -0
- package/docs/api/computed.html +184 -0
- package/docs/api/effects.html +173 -0
- package/docs/api/elements.html +180 -0
- package/docs/api/enhance.html +225 -0
- package/docs/api/hypermedia.html +165 -0
- package/docs/api/index.html +178 -0
- package/docs/api/nav.html +18 -0
- package/docs/api/signals.html +136 -0
- package/docs/api/state.html +217 -0
- package/docs/assets/images/logo-favicon.svg +42 -0
- package/docs/assets/images/logo-static.svg +40 -0
- package/docs/assets/images/logo.svg +66 -0
- package/docs/assets/js/examplify.js +395 -0
- package/docs/assets/styles/site.css +1102 -0
- package/docs/assets/styles/themes.css +236 -0
- package/docs/components/accordion.html +439 -0
- package/docs/components/alert.html +528 -0
- package/docs/components/avatar.html +586 -0
- package/docs/components/badge.html +531 -0
- package/docs/components/breadcrumbs.html +278 -0
- package/docs/components/button.html +579 -0
- package/docs/components/card.html +561 -0
- package/docs/components/carousel.html +286 -0
- package/docs/components/chart-area.html +702 -0
- package/docs/components/chart-bar.html +782 -0
- package/docs/components/chart-column.html +735 -0
- package/docs/components/chart-line.html +794 -0
- package/docs/components/chart-pie.html +823 -0
- package/docs/components/chart.html +610 -15
- package/docs/components/chat.html +547 -0
- package/docs/components/checkbox.html +641 -0
- package/docs/components/collapse.html +536 -0
- package/docs/components/component-nav.html +53 -0
- package/docs/components/countdown.html +470 -0
- package/docs/components/diff.html +245 -0
- package/docs/components/divider.html +240 -0
- package/docs/components/dock.html +277 -0
- package/docs/components/drawer.html +515 -0
- package/docs/components/dropdown.html +479 -0
- package/docs/components/file-input.html +591 -0
- package/docs/components/footer.html +301 -0
- package/docs/components/gallery.html +504 -0
- package/docs/components/hero.html +264 -0
- package/docs/components/index.css +840 -0
- package/docs/components/index.html +735 -0
- package/docs/components/indicator.html +342 -0
- package/docs/components/input.html +644 -0
- package/docs/components/join.html +285 -0
- package/docs/components/kbd.html +322 -0
- package/docs/components/loading.html +521 -0
- package/docs/components/menu.html +461 -0
- package/docs/components/modal.html +639 -0
- package/docs/components/navbar.html +321 -0
- package/docs/components/pagination.html +279 -0
- package/docs/components/progress.html +514 -0
- package/docs/components/radial-progress.html +434 -0
- package/docs/components/radio.html +655 -0
- package/docs/components/range.html +611 -0
- package/docs/components/rating.html +642 -0
- package/docs/components/select.html +696 -0
- package/docs/components/sidebar-setup.js +93 -0
- package/docs/components/skeleton.html +447 -0
- package/docs/components/spinner.html +68 -0
- package/docs/components/stats.html +486 -0
- package/docs/components/steps.html +356 -0
- package/docs/components/swap.html +517 -0
- package/docs/components/switch.html +68 -0
- package/docs/components/table.html +668 -0
- package/docs/components/tabs.html +506 -0
- package/docs/components/text-input.html +68 -0
- package/docs/components/textarea.html +603 -0
- package/docs/components/timeline.html +485 -42
- package/docs/components/toast.html +474 -0
- package/docs/components/toggle.html +564 -0
- package/docs/components/tooltip.html +423 -0
- package/docs/examples/getting-started-example.html +40 -0
- package/docs/examples/index.html +93 -0
- package/docs/getting-started/index.html +739 -0
- package/docs/getting-started/reviews.html +23 -0
- package/docs/getting-started/reviews.odom +108 -0
- package/docs/getting-started/reviews.vdom +84 -0
- package/docs/index.html +132 -42
- package/docs/playground.html +416 -0
- package/docs/router.html +285 -0
- package/docs/styles/index.html +190 -0
- package/functions/_middleware.js +32 -0
- package/index.html +309 -0
- package/lightview-router.js +364 -0
- package/lightview-x.js +1577 -0
- package/lightview.js +659 -1200
- package/middleware/locale.js +25 -0
- package/middleware/markdown.js +44 -0
- package/middleware/notFound.js +37 -0
- package/package.json +27 -41
- package/watch.js +92 -0
- package/wrangler.toml +12 -0
- package/.idea/lightview.iml +0 -12
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/LICENSE +0 -21
- package/codepen-no-tabs-embed.css +0 -2
- package/docs/CNAME +0 -1
- package/docs/api.html +0 -674
- package/docs/blank.html +0 -10
- package/docs/comparedto.html +0 -89
- package/docs/components/chart-repl.html +0 -69
- package/docs/components/components.js +0 -113
- package/docs/components/contents.html +0 -17
- package/docs/components/gantt-repl.html +0 -61
- package/docs/components/gantt.html +0 -42
- package/docs/components/gauge-repl.html +0 -66
- package/docs/components/gauge.html +0 -20
- package/docs/components/orgchart-repl.html +0 -64
- package/docs/components/orgchart.html +0 -41
- package/docs/components/repl-as-src.html +0 -17
- package/docs/components/repl-repl.html +0 -95
- package/docs/components/repl.html +0 -527
- package/docs/components/timeline-repl.html +0 -72
- package/docs/components.html +0 -14
- package/docs/css/highlightjs.min.css +0 -9
- package/docs/css/tutorial.css +0 -35
- package/docs/examples/anchor.html +0 -11
- package/docs/examples/chart.html +0 -34
- package/docs/examples/counter.html +0 -26
- package/docs/examples/counter.test.mjs +0 -47
- package/docs/examples/counter2.html +0 -26
- package/docs/examples/directives.html +0 -79
- package/docs/examples/foreign.html +0 -50
- package/docs/examples/forgeinform.html +0 -98
- package/docs/examples/form.html +0 -61
- package/docs/examples/gauge.html +0 -18
- package/docs/examples/invalid-template-literals.html +0 -44
- package/docs/examples/medium/remote.html +0 -60
- package/docs/examples/message.html +0 -18
- package/docs/examples/nested.html +0 -11
- package/docs/examples/object-bound-form.html +0 -34
- package/docs/examples/remote-server.js +0 -51
- package/docs/examples/remote.html +0 -34
- package/docs/examples/remote.json +0 -1
- package/docs/examples/scratch.html +0 -69
- package/docs/examples/sensors/index.html +0 -44
- package/docs/examples/sensors/sensor-server.js +0 -30
- package/docs/examples/shared.html +0 -41
- package/docs/examples/template.html +0 -33
- package/docs/examples/timeline.html +0 -21
- package/docs/examples/todo.html +0 -40
- package/docs/examples/top.html +0 -10
- package/docs/examples/types.html +0 -94
- package/docs/examples/xor.html +0 -62
- package/docs/examples.html +0 -25
- package/docs/javascript/codejar.min.js +0 -8
- package/docs/javascript/highlightjs.min.js +0 -1173
- package/docs/javascript/isomorphic-git.js +0 -9
- package/docs/javascript/json5.min.js +0 -1
- package/docs/javascript/lightning-fs.js +0 -1
- package/docs/javascript/lightview.js +0 -1285
- package/docs/javascript/marked.min.js +0 -6
- package/docs/javascript/peerjs.min.js +0 -70
- package/docs/javascript/turndown.js +0 -973
- package/docs/javascript/types.js +0 -606
- package/docs/javascript/utils.js +0 -45
- package/docs/lightview.html +0 -63
- package/docs/old_index.html +0 -965
- package/docs/old_index.md +0 -1132
- package/docs/slidein.html +0 -51
- package/docs/tutorial/0-getting-started.html +0 -67
- package/docs/tutorial/1-intro-to-variables.html +0 -103
- package/docs/tutorial/10-template-components.html +0 -80
- package/docs/tutorial/11-linked-components.html +0 -76
- package/docs/tutorial/12-imported-components.html +0 -67
- package/docs/tutorial/13-input-binding.html +0 -94
- package/docs/tutorial/14-automatic-variable-creation.html +0 -74
- package/docs/tutorial/15-form-binding.html +0 -110
- package/docs/tutorial/16-if-directive.html +0 -60
- package/docs/tutorial/17-loop-directives.html +0 -83
- package/docs/tutorial/18-sanitizing-and-escaping-input.html +0 -79
- package/docs/tutorial/2-imported-and-exported-variables.html +0 -80
- package/docs/tutorial/3-data-types.html +0 -89
- package/docs/tutorial/4-extended-data-types.html +0 -83
- package/docs/tutorial/5-extended-functional-types.html +0 -96
- package/docs/tutorial/5.1-extended-functional-types.html +0 -79
- package/docs/tutorial/5.2-extended-functional-types.html +0 -70
- package/docs/tutorial/6-conventional-javascript.html +0 -75
- package/docs/tutorial/7-monitoring-with-observers.html +0 -107
- package/docs/tutorial/8-event-listeners.html +0 -65
- package/docs/tutorial/9-intro-to-components.html +0 -91
- package/docs/tutorial/contents.html +0 -32
- package/docs/tutorial/my-component.html +0 -29
- package/docs/tutorial/remote-value.json +0 -4
- package/docs/websiterepl.html +0 -46
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.json +0 -12
- package/lightview.min.js +0 -1
- package/lightview_good.js +0 -1267
- package/lightview_optimized.js +0 -1274
- package/repl_hold.html +0 -320
- package/test/basic.html +0 -104
- package/test/basic.test.mjs +0 -315
- package/test/extended.html +0 -29
- package/test/extended.test.mjs +0 -448
- package/types.js +0 -607
- package/unsplash.key +0 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
<!-- SEO-friendly SPA Shim -->
|
|
2
|
+
<script src="/lightview-router.js"></script>
|
|
3
|
+
<script>
|
|
4
|
+
if (window.LightviewRouter) {
|
|
5
|
+
LightviewRouter.base('/index.html');
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<link rel="stylesheet" href="../components/index.css">
|
|
10
|
+
|
|
11
|
+
<div class="docs-layout">
|
|
12
|
+
<aside class="docs-sidebar" src="./nav.html"></aside>
|
|
13
|
+
|
|
14
|
+
<main class="docs-content">
|
|
15
|
+
<h1>Enhance</h1>
|
|
16
|
+
<p>
|
|
17
|
+
The <code>enhance()</code> function lets you add Lightview's reactivity to existing HTML elements.
|
|
18
|
+
Perfect for progressive enhancement - start with plain HTML and add interactivity where needed.
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<h2>Why Enhance?</h2>
|
|
22
|
+
<p>
|
|
23
|
+
Sometimes you have existing HTML - maybe from a CMS, a server-rendered template, or just plain HTML.
|
|
24
|
+
Rather than rebuilding everything with Lightview elements, <code>enhance()</code> lets you
|
|
25
|
+
incrementally add reactivity to what's already there.
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<h2>Basic Usage</h2>
|
|
29
|
+
<pre><code>const { signal, enhance } = Lightview;
|
|
30
|
+
|
|
31
|
+
// Select an existing element and make it reactive
|
|
32
|
+
const counter = signal(0);
|
|
33
|
+
enhance('#my-element', {
|
|
34
|
+
innerText: () => `Count: ${counter.value}`
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Now when counter changes, the element updates automatically!</code></pre>
|
|
38
|
+
|
|
39
|
+
<h2>Syntax</h2>
|
|
40
|
+
<pre><code>enhance(selectorOrNode, options)
|
|
41
|
+
|
|
42
|
+
// selectorOrNode: CSS selector string or DOM element
|
|
43
|
+
// options: { innerText?, innerHTML?, ...attributes }
|
|
44
|
+
|
|
45
|
+
// Returns: Lightview element wrapper (or null if not found)</code></pre>
|
|
46
|
+
|
|
47
|
+
<h2>Live Example: Basic Enhancement</h2>
|
|
48
|
+
<pre><script>
|
|
49
|
+
examplify(document.currentScript.nextElementSibling, {
|
|
50
|
+
at: document.currentScript.parentElement,
|
|
51
|
+
scripts: ['/lightview.js'],
|
|
52
|
+
type: 'module',
|
|
53
|
+
minHeight: 180,
|
|
54
|
+
html: `<!-- This HTML exists in the page before enhancement -->
|
|
55
|
+
<div id="greeting-card" style="padding: 1rem; background: #f8f9fa; border-radius: 8px; border: 1px solid #dee2e6;">
|
|
56
|
+
<h3 id="greeting-title">Welcome!</h3>
|
|
57
|
+
<p id="greeting-message">Enter your name below</p>
|
|
58
|
+
<input id="name-input" type="text" placeholder="Your name..." style="width: 100%; padding: 0.5rem; margin: 0.5rem 0; border: 1px solid #ccc; border-radius: 4px;">
|
|
59
|
+
<button id="reset-btn" style="padding: 0.5rem 1rem; background: #6c757d; color: white; border: none; border-radius: 4px; cursor: pointer;">Reset</button>
|
|
60
|
+
</div>`
|
|
61
|
+
});
|
|
62
|
+
</script><code contenteditable="true">const { signal, enhance } = Lightview;
|
|
63
|
+
|
|
64
|
+
const name = signal('');
|
|
65
|
+
|
|
66
|
+
// Enhance the input field
|
|
67
|
+
enhance('#name-input', {
|
|
68
|
+
oninput: (e) => name.value = e.target.value,
|
|
69
|
+
value: () => name.value
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Enhance the greeting title
|
|
73
|
+
enhance('#greeting-title', {
|
|
74
|
+
innerText: () => name.value ? `Hello, ${name.value}!` : 'Welcome!'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Enhance the greeting message
|
|
78
|
+
enhance('#greeting-message', {
|
|
79
|
+
innerText: () => name.value
|
|
80
|
+
? `Nice to meet you, ${name.value}!`
|
|
81
|
+
: 'Enter your name below',
|
|
82
|
+
style: () => name.value
|
|
83
|
+
? 'color: #28a745; font-weight: 500;'
|
|
84
|
+
: 'color: #6c757d;'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Enhance the reset button
|
|
88
|
+
enhance('#reset-btn', {
|
|
89
|
+
onclick: () => name.value = '',
|
|
90
|
+
disabled: () => !name.value,
|
|
91
|
+
style: () => `padding: 0.5rem 1rem; background: ${name.value ? '#dc3545' : '#6c757d'}; color: white; border: none; border-radius: 4px; cursor: ${name.value ? 'pointer' : 'not-allowed'}; opacity: ${name.value ? 1 : 0.5};`
|
|
92
|
+
});</code></pre>
|
|
93
|
+
|
|
94
|
+
<h2>Options</h2>
|
|
95
|
+
|
|
96
|
+
<h3>innerText</h3>
|
|
97
|
+
<p>Replace the text content of an element. Can be static or reactive:</p>
|
|
98
|
+
<pre><code>// Static text
|
|
99
|
+
enhance('#greeting', { innerText: 'Hello World' });
|
|
100
|
+
|
|
101
|
+
// Reactive text - updates when signal changes
|
|
102
|
+
const name = signal('Alice');
|
|
103
|
+
enhance('#greeting', { innerText: () => `Hello ${name.value}` });</code></pre>
|
|
104
|
+
|
|
105
|
+
<h3>innerHTML</h3>
|
|
106
|
+
<p>Replace the HTML content. Use with caution - only with trusted content:</p>
|
|
107
|
+
<pre><code>const html = signal('<strong>Bold text</strong>');
|
|
108
|
+
enhance('#content', { innerHTML: () => html.value });</code></pre>
|
|
109
|
+
|
|
110
|
+
<h3>Attributes</h3>
|
|
111
|
+
<p>Any other properties in options are treated as attributes. These can also be reactive:</p>
|
|
112
|
+
<pre><code>const isDisabled = signal(false);
|
|
113
|
+
const theme = signal('light');
|
|
114
|
+
|
|
115
|
+
enhance('#my-button', {
|
|
116
|
+
disabled: () => isDisabled.value,
|
|
117
|
+
class: () => `btn btn-${theme.value}`,
|
|
118
|
+
'data-active': () => !isDisabled.value
|
|
119
|
+
});</code></pre>
|
|
120
|
+
|
|
121
|
+
<h2>Live Example: Reactive Attributes</h2>
|
|
122
|
+
<pre><script>
|
|
123
|
+
examplify(document.currentScript.nextElementSibling, {
|
|
124
|
+
at: document.currentScript.parentElement,
|
|
125
|
+
scripts: ['/lightview.js', '/lightview-x.js'],
|
|
126
|
+
type: 'module',
|
|
127
|
+
maxHeight: 50,
|
|
128
|
+
html: `
|
|
129
|
+
<span id="attr-demo">
|
|
130
|
+
<button id="toggle-btn">Enable/Disable</button>
|
|
131
|
+
<button id="target-btn">Target Button</button>
|
|
132
|
+
</span>`
|
|
133
|
+
});
|
|
134
|
+
</script><code contenteditable="true">const { signal, enhance, tags } = Lightview;
|
|
135
|
+
const { div } = tags;
|
|
136
|
+
|
|
137
|
+
const disabled = signal(false);
|
|
138
|
+
|
|
139
|
+
enhance('#toggle-btn', {
|
|
140
|
+
onclick: () => disabled.value = !disabled.value,
|
|
141
|
+
innerText: () => disabled.value ? 'Enable' : 'Disable'
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
enhance('#target-btn', {
|
|
145
|
+
disabled: () => disabled.value,
|
|
146
|
+
style: () => `opacity: ${disabled.value ? 0.5 : 1}; cursor: ${disabled.value ? 'not-allowed' : 'pointer'};`
|
|
147
|
+
});</code></pre>
|
|
148
|
+
|
|
149
|
+
<h2>Progressive Enhancement Pattern</h2>
|
|
150
|
+
<p>
|
|
151
|
+
Start with semantic HTML that works without JavaScript, then enhance with Lightview:
|
|
152
|
+
</p>
|
|
153
|
+
<pre><code><!-- server-rendered HTML -->
|
|
154
|
+
<div id="user-info">
|
|
155
|
+
<h2>Guest</h2>
|
|
156
|
+
<p>Please log in</p>
|
|
157
|
+
</div>
|
|
158
|
+
|
|
159
|
+
<script>
|
|
160
|
+
// Enhancement kicks in when JS loads
|
|
161
|
+
const { signal, enhance } = Lightview;
|
|
162
|
+
const user = signal(null);
|
|
163
|
+
|
|
164
|
+
// Fetch user data
|
|
165
|
+
fetch('/api/user').then(r => r.json()).then(data => {
|
|
166
|
+
user.value = data;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Enhance the existing markup
|
|
170
|
+
enhance('#user-info h2', {
|
|
171
|
+
innerText: () => user.value?.name ?? 'Guest'
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
enhance('#user-info p', {
|
|
175
|
+
innerText: () => user.value
|
|
176
|
+
? `Welcome back, ${user.value.name}!`
|
|
177
|
+
: 'Please log in'
|
|
178
|
+
});
|
|
179
|
+
</script></code></pre>
|
|
180
|
+
|
|
181
|
+
<h2>Return Value</h2>
|
|
182
|
+
<p>
|
|
183
|
+
<code>enhance()</code> returns a Lightview element wrapper with a <code>domEl</code> property
|
|
184
|
+
pointing to the actual DOM node. This lets you further manipulate it:
|
|
185
|
+
</p>
|
|
186
|
+
<pre><code>const el = enhance('#my-div', { class: 'enhanced' });
|
|
187
|
+
|
|
188
|
+
// Access the wrapped element
|
|
189
|
+
if (el) {
|
|
190
|
+
console.log(el.domEl); // The actual DOM node
|
|
191
|
+
el.attributes.id = 'new-id'; // Update attributes reactively
|
|
192
|
+
}</code></pre>
|
|
193
|
+
|
|
194
|
+
<h2>Tips & Patterns</h2>
|
|
195
|
+
|
|
196
|
+
<h3>Enhance Multiple Elements</h3>
|
|
197
|
+
<pre><code>// Enhance a list of elements
|
|
198
|
+
document.querySelectorAll('.counter').forEach(el => {
|
|
199
|
+
const count = signal(0);
|
|
200
|
+
enhance(el, {
|
|
201
|
+
innerText: () => count.value,
|
|
202
|
+
onclick: () => count.value++
|
|
203
|
+
});
|
|
204
|
+
});</code></pre>
|
|
205
|
+
|
|
206
|
+
<h3>Reusing Elements</h3>
|
|
207
|
+
<p>If you call <code>enhance()</code> on an already-enhanced element, it merges the new options:</p>
|
|
208
|
+
<pre><code>// First enhancement
|
|
209
|
+
enhance('#btn', { innerText: 'Click me' });
|
|
210
|
+
|
|
211
|
+
// Second enhancement - adds to the first
|
|
212
|
+
enhance('#btn', { onclick: "alert('clicked')" });
|
|
213
|
+
|
|
214
|
+
// Result: <button onclick="alert('clicked')">Click me</button></code></pre>
|
|
215
|
+
|
|
216
|
+
<h3>When to Use</h3>
|
|
217
|
+
<ul>
|
|
218
|
+
<li><strong>Use enhance():</strong> When you have existing HTML (server-rendered, CMS, etc.)</li>
|
|
219
|
+
<li><strong>Use element/tags:</strong> When building new UI from scratch in JavaScript</li>
|
|
220
|
+
<li><strong>Mix both:</strong> Enhance static structure, build dynamic parts with tags</li>
|
|
221
|
+
</ul>
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
</main>
|
|
225
|
+
</div>
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<!-- SEO-friendly SPA Shim -->
|
|
2
|
+
<script src="/lightview-router.js"></script>
|
|
3
|
+
<script>
|
|
4
|
+
if (window.LightviewRouter) {
|
|
5
|
+
LightviewRouter.base('/index.html');
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<div class="docs-layout">
|
|
10
|
+
<aside class="docs-sidebar" src="./nav.html"></aside>
|
|
11
|
+
|
|
12
|
+
<main class="docs-content">
|
|
13
|
+
<h1>Hypermedia</h1>
|
|
14
|
+
<p>
|
|
15
|
+
HTMX vibes, built right in. Load HTML fragments, fetch vDOM/Object DOM, clone templates - all with the
|
|
16
|
+
<code>src</code>
|
|
17
|
+
attribute.
|
|
18
|
+
<em>Requires lightview-x.js</em>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<h2>Fetching HTML</h2>
|
|
22
|
+
<p>
|
|
23
|
+
Point <code>src</code> at an HTML file and Lightview loads it as children:
|
|
24
|
+
</p>
|
|
25
|
+
<pre><code>const { tags } = Lightview;
|
|
26
|
+
const { div, header, main } = tags;
|
|
27
|
+
|
|
28
|
+
// Load HTML partials
|
|
29
|
+
const app = div(
|
|
30
|
+
header({ src: '/partials/nav.html' }),
|
|
31
|
+
main({ src: '/partials/content.html' })
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
// The HTML is fetched, parsed, and made reactive automatically!</code></pre>
|
|
35
|
+
|
|
36
|
+
<h2>Fetching vDOM & Object DOM</h2>
|
|
37
|
+
<p>
|
|
38
|
+
Files with <code>.vdom</code> or <code>.odom</code> extensions are parsed as JSON and converted to elements:
|
|
39
|
+
</p>
|
|
40
|
+
<pre><code>// /api/cards.vdom
|
|
41
|
+
[
|
|
42
|
+
{ "tag": "div", "attributes": { "class": "card" }, "children": ["Card 1"] },
|
|
43
|
+
{ "tag": "div", "attributes": { "class": "card" }, "children": ["Card 2"] }
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
// Load vDOM
|
|
47
|
+
div({ src: '/api/cards.vdom' })</code></pre>
|
|
48
|
+
|
|
49
|
+
<h2>Cloning DOM Elements</h2>
|
|
50
|
+
<p>
|
|
51
|
+
Use CSS selectors to clone existing elements:
|
|
52
|
+
</p>
|
|
53
|
+
<pre><code>// Clone a template
|
|
54
|
+
div({ src: '#my-template' })
|
|
55
|
+
|
|
56
|
+
// Clone multiple elements
|
|
57
|
+
div({ src: '.card-template' })</code></pre>
|
|
58
|
+
<pre><code><!-- Hidden template in HTML -->
|
|
59
|
+
<template id="my-template">
|
|
60
|
+
<div class="modal">
|
|
61
|
+
<h2>Modal Title</h2>
|
|
62
|
+
<p>Modal content here</p>
|
|
63
|
+
</div>
|
|
64
|
+
</template></code></pre>
|
|
65
|
+
|
|
66
|
+
<h2>Interactive href & Navigation</h2>
|
|
67
|
+
<p>
|
|
68
|
+
Add <code>href</code> to any element to make it interactive. The behavior depends on the <code>target</code>
|
|
69
|
+
attribute:
|
|
70
|
+
</p>
|
|
71
|
+
|
|
72
|
+
<h3>1. Self-Loading (Default)</h3>
|
|
73
|
+
<p>If no target is specified, clicking sets the element's own <code>src</code> to the <code>href</code> value:
|
|
74
|
+
</p>
|
|
75
|
+
<pre><code>// Loads content into itself on click
|
|
76
|
+
button({ href: '/partials/data.html' }, 'Load Data')</code></pre>
|
|
77
|
+
|
|
78
|
+
<h3>2. Browser Navigation</h3>
|
|
79
|
+
<p>Use standard underscore targets for window navigation:</p>
|
|
80
|
+
<pre><code>// Opens new tab
|
|
81
|
+
button({ href: 'https://example.com', target: '_blank' }, 'Open External')
|
|
82
|
+
|
|
83
|
+
// Navigates current page
|
|
84
|
+
div({ href: '/home', target: '_self' }, 'Go Home')</code></pre>
|
|
85
|
+
|
|
86
|
+
<h3>3. Targeting Other Elements</h3>
|
|
87
|
+
<p>Use a CSS selector as the target to load content into other elements:</p>
|
|
88
|
+
<pre><code>// Loads content into element with id="main"
|
|
89
|
+
button({ href: '/pages/about.html', target: '#main' }, 'Load About Page')
|
|
90
|
+
|
|
91
|
+
div({ id: 'main' }) // Content appears here</code></pre>
|
|
92
|
+
|
|
93
|
+
<h3>4. Positioning Content</h3>
|
|
94
|
+
<p>Control where content is inserted using the <code>location</code> attribute or a target suffix.</p>
|
|
95
|
+
<p><strong>Supported locations:</strong> <code>innerhtml</code> (default), <code>outerhtml</code>,
|
|
96
|
+
<code>beforebegin</code>, <code>afterbegin</code>, <code>beforeend</code>, <code>afterend</code>,
|
|
97
|
+
<code>shadow</code>.
|
|
98
|
+
</p>
|
|
99
|
+
|
|
100
|
+
<pre><code>// Option A: Suffix syntax for href (Target Selector:Location)
|
|
101
|
+
button({
|
|
102
|
+
href: '/partials/item.html',
|
|
103
|
+
target: '#list:beforeend' // Append to list
|
|
104
|
+
}, 'Add Item')
|
|
105
|
+
|
|
106
|
+
// Option B: Explicit attribute on target for src
|
|
107
|
+
div({
|
|
108
|
+
src: '/partials/banner.html',
|
|
109
|
+
location: 'afterbegin'
|
|
110
|
+
})</code></pre>
|
|
111
|
+
|
|
112
|
+
<p><strong>Smart Replacement:</strong> Lightview tracks inserted content. Fetching the same content to the same
|
|
113
|
+
location is a no-op. Fetching different content replaces the previous content at that specific location.</p>
|
|
114
|
+
|
|
115
|
+
<h2>HTML Template Literals</h2>
|
|
116
|
+
<p>
|
|
117
|
+
External HTML can reference named signals or state with template syntax:
|
|
118
|
+
</p>
|
|
119
|
+
<pre><code>// main.js - Register named signals and state
|
|
120
|
+
const count = signal(0, 'count');
|
|
121
|
+
const userName = signal('Guest', 'userName');
|
|
122
|
+
const userPrefs = state({ theme: 'dark', lang: 'en' }, 'userPrefs');
|
|
123
|
+
|
|
124
|
+
// Load template that uses them
|
|
125
|
+
div({ src: '/partials/dashboard.html' })</code></pre>
|
|
126
|
+
<pre><code><!-- /partials/dashboard.html -->
|
|
127
|
+
<div class="dashboard">
|
|
128
|
+
<h1>Welcome, ${signal.get('userName').value}!</h1>
|
|
129
|
+
<p>You have ${signal.get('count').value} notifications.</p>
|
|
130
|
+
<p>Theme: ${state.get('userPrefs').theme}</p>
|
|
131
|
+
</div></code></pre>
|
|
132
|
+
|
|
133
|
+
<h2>Shadow DOM</h2>
|
|
134
|
+
<p>
|
|
135
|
+
Load content into shadow DOM for style isolation using <code>location="shadow"</code> or the
|
|
136
|
+
<code>:shadow</code> suffix:
|
|
137
|
+
</p>
|
|
138
|
+
<pre><code>// Option A: location attribute
|
|
139
|
+
div({ src: '/components/widget.html', location: 'shadow' })
|
|
140
|
+
|
|
141
|
+
// Option B: target suffix
|
|
142
|
+
button({ href: '/components/widget.html', target: '#container:shadow' }, 'Load Widget')</code></pre>
|
|
143
|
+
|
|
144
|
+
<h2>Building HTMX-style Apps</h2>
|
|
145
|
+
<p>
|
|
146
|
+
Combine <code>src</code> and <code>href</code> for hypermedia-driven UIs:
|
|
147
|
+
</p>
|
|
148
|
+
<pre><code>const { tags } = Lightview;
|
|
149
|
+
const { div, nav, button, main } = tags;
|
|
150
|
+
|
|
151
|
+
const app = div({ class: 'app' },
|
|
152
|
+
nav({ class: 'sidebar' },
|
|
153
|
+
button({ href: '/pages/dashboard.html' }, '📊 Dashboard'),
|
|
154
|
+
button({ href: '/pages/settings.html' }, '⚙️ Settings'),
|
|
155
|
+
button({ href: '/pages/profile.html' }, '👤 Profile')
|
|
156
|
+
),
|
|
157
|
+
main({
|
|
158
|
+
id: 'content',
|
|
159
|
+
src: '/pages/dashboard.html' // Initial content
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
</main>
|
|
165
|
+
</div>
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<!-- SEO-friendly SPA Shim -->
|
|
2
|
+
<script src="/lightview-router.js"></script>
|
|
3
|
+
<script>
|
|
4
|
+
if (window.LightviewRouter) {
|
|
5
|
+
LightviewRouter.base('/index.html');
|
|
6
|
+
}
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<div class="docs-layout">
|
|
12
|
+
<aside class="docs-sidebar" src="./nav.html"></aside>
|
|
13
|
+
|
|
14
|
+
<main class="docs-content">
|
|
15
|
+
<h1>API Reference</h1>
|
|
16
|
+
<p>
|
|
17
|
+
Lightview provides a small but powerful API. Everything you need, nothing you don't.
|
|
18
|
+
<em>Keep it light, remember?</em>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<h2>Lightview Overview</h2>
|
|
22
|
+
|
|
23
|
+
<table class="api-table">
|
|
24
|
+
<thead>
|
|
25
|
+
<tr>
|
|
26
|
+
<th>Function</th>
|
|
27
|
+
<th>Description</th>
|
|
28
|
+
</tr>
|
|
29
|
+
</thead>
|
|
30
|
+
<tbody>
|
|
31
|
+
<tr>
|
|
32
|
+
<td><a
|
|
33
|
+
href="./signals.html"><code>signal(value, optionsOrName?)</code></a><br><code>signal.get(name)</code>
|
|
34
|
+
</td>
|
|
35
|
+
<td>Create reactive state that triggers updates when changed. Optional name or options object allows
|
|
36
|
+
global access and persistence.
|
|
37
|
+
</td>
|
|
38
|
+
</tr>
|
|
39
|
+
<tr>
|
|
40
|
+
<td><a href="./computed.html"><code>computed(fn)</code></a></td>
|
|
41
|
+
<td>Derive values from signals automatically</td>
|
|
42
|
+
</tr>
|
|
43
|
+
<tr>
|
|
44
|
+
<td><a href="./effects.html"><code>effect(fn)</code></a></td>
|
|
45
|
+
<td>Run side effects when dependencies change</td>
|
|
46
|
+
</tr>
|
|
47
|
+
<tr>
|
|
48
|
+
<td><a href="./elements.html"><code>tags.*</code></a></td>
|
|
49
|
+
<td>Shorthand element creators (div, span, button, etc.)</td>
|
|
50
|
+
</tr>
|
|
51
|
+
<tr>
|
|
52
|
+
<td><code>$(selector)</code></td>
|
|
53
|
+
<td>Query the DOM and return a native element enhanced with a <code>.content(node, location?)</code>
|
|
54
|
+
method.
|
|
55
|
+
The <code>location</code> can be <code>'inner'</code> (default), <code>'outer'</code>,
|
|
56
|
+
<code>'shadow'</code>,
|
|
57
|
+
<code>'beforebegin'</code>, <code>'afterbegin'</code>, <code>'beforeend'</code>, or
|
|
58
|
+
<code>'afterend'</code>.
|
|
59
|
+
The <code>node</code> argument is polymorphic and can be a real DOM node, a virtual node (vDOM),
|
|
60
|
+
Object DOM, or an array of these.
|
|
61
|
+
</td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td><a href="./enhance.html"><code>enhance(selector, options)</code></a></td>
|
|
65
|
+
<td>Add reactivity to existing DOM elements. Perfect for progressive enhancement of traditional HTML
|
|
66
|
+
pages.</td>
|
|
67
|
+
</tr>
|
|
68
|
+
</tbody>
|
|
69
|
+
</table>
|
|
70
|
+
|
|
71
|
+
<h2>Lightview X Overview</h2>
|
|
72
|
+
<p>
|
|
73
|
+
Lightview X automatically enhances the core Lightview instance when loaded, adding hypermedia capabilities,
|
|
74
|
+
template literal support, and deep reactive state. Object DOM syntax is now always available in core
|
|
75
|
+
Lightview.
|
|
76
|
+
</p>
|
|
77
|
+
|
|
78
|
+
<table class="api-table">
|
|
79
|
+
<thead>
|
|
80
|
+
<tr>
|
|
81
|
+
<th>Feature / Function</th>
|
|
82
|
+
<th>Description</th>
|
|
83
|
+
</tr>
|
|
84
|
+
</thead>
|
|
85
|
+
<tbody>
|
|
86
|
+
<tr>
|
|
87
|
+
<td><a
|
|
88
|
+
href="./state.html"><code>state(obj, optionsOrName?)</code></a><br><code>state.get(name)</code>
|
|
89
|
+
</td>
|
|
90
|
+
<td>Create deep reactive state for complex objects/arrays. Optional name or options object allows
|
|
91
|
+
global access and persistence.</td>
|
|
92
|
+
</tr>
|
|
93
|
+
<tr>
|
|
94
|
+
<td><code>registerStyleSheet(id, css)</code></td>
|
|
95
|
+
<td>Register a named stylesheet for use in Shadow DOM components. Can take a CSS string, a URL, or a
|
|
96
|
+
selector to a <code><style></code> tag.</td>
|
|
97
|
+
</tr>
|
|
98
|
+
<tr>
|
|
99
|
+
<td><code>registerThemeSheet(url)</code></td>
|
|
100
|
+
<td>Register a global theme stylesheet that is automatically applied to all Shadow DOM components.
|
|
101
|
+
</td>
|
|
102
|
+
</tr>
|
|
103
|
+
<tr>
|
|
104
|
+
<td><a href="./hypermedia.html"><code>src="..."</code></a></td>
|
|
105
|
+
<td>Attribute to automatically fetch HTML or JSON representing HTML and inject it into the element.
|
|
106
|
+
</td>
|
|
107
|
+
</tr>
|
|
108
|
+
<tr>
|
|
109
|
+
<td><a href="./hypermedia.html"><code>href="..."</code></a></td>
|
|
110
|
+
<td>Attribute for SPA navigation and src injection on any element. Supports targeting content
|
|
111
|
+
before, at the start of, and the end of or after other elements via CSS selectors.</td>
|
|
112
|
+
</tr>
|
|
113
|
+
<tr>
|
|
114
|
+
<td>
|
|
115
|
+
<code><div>${signal.get('count').value}</div></code><br><code><span>${state.get('user').name}</span></code>
|
|
116
|
+
</td>
|
|
117
|
+
<td>Syntax support for using signals and state directly inside string templates in HTML or JSON
|
|
118
|
+
representation of HTML.</td>
|
|
119
|
+
</tr>
|
|
120
|
+
</tbody>
|
|
121
|
+
</table>
|
|
122
|
+
|
|
123
|
+
<h2>Using Lightview</h2>
|
|
124
|
+
<pre><code><!-- Core only -->
|
|
125
|
+
<script src="lightview.js"></script>
|
|
126
|
+
|
|
127
|
+
<!-- Full power -->
|
|
128
|
+
<script src="lightview.js"></script>
|
|
129
|
+
<script src="lightview-x.js"></script></code></pre>
|
|
130
|
+
<pre><code>// Destructure what you need from the global instances
|
|
131
|
+
const { signal, computed, effect, element, tags, $, enhance } = Lightview;
|
|
132
|
+
const { state } = LightviewX; // Deep state (lightview-x)</code></pre>
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
<h2>Core Modules</h2>
|
|
137
|
+
|
|
138
|
+
<div class="feature-grid" style="margin-top: 1.5rem;">
|
|
139
|
+
<a href="./signals" class="feature-card" style="text-decoration: none; color: inherit;">
|
|
140
|
+
<h3 class="feature-title">Signals</h3>
|
|
141
|
+
<p class="feature-description">
|
|
142
|
+
The foundation. Reactive primitives that make everything tick.
|
|
143
|
+
</p>
|
|
144
|
+
</a>
|
|
145
|
+
<a href="./computed" class="feature-card" style="text-decoration: none; color: inherit;">
|
|
146
|
+
<h3 class="feature-title">Computed</h3>
|
|
147
|
+
<p class="feature-description">
|
|
148
|
+
Derived state. Values that update themselves.
|
|
149
|
+
</p>
|
|
150
|
+
</a>
|
|
151
|
+
<a href="./effects" class="feature-card" style="text-decoration: none; color: inherit;">
|
|
152
|
+
<h3 class="feature-title">Effects</h3>
|
|
153
|
+
<p class="feature-description">
|
|
154
|
+
Side effects. Do things when state changes.
|
|
155
|
+
</p>
|
|
156
|
+
</a>
|
|
157
|
+
<a href="./elements" class="feature-card" style="text-decoration: none; color: inherit;">
|
|
158
|
+
<h3 class="feature-title">Elements</h3>
|
|
159
|
+
<p class="feature-description">
|
|
160
|
+
Three ways to build UI, tag functions, vDOM, and Object DOM. Pick your favorite.
|
|
161
|
+
</p>
|
|
162
|
+
</a>
|
|
163
|
+
<a href="./enhance" class="feature-card" style="text-decoration: none; color: inherit;">
|
|
164
|
+
<h3 class="feature-title">Enhance</h3>
|
|
165
|
+
<p class="feature-description">
|
|
166
|
+
Add reactivity to existing HTML. Progressive enhancement made easy.
|
|
167
|
+
</p>
|
|
168
|
+
</a>
|
|
169
|
+
<a href="./hypermedia.html" class="feature-card" style="text-decoration: none; color: inherit;">
|
|
170
|
+
<h3 class="feature-title">Hypermedia</h3>
|
|
171
|
+
<p class="feature-description">
|
|
172
|
+
Fetch content with src. HTMX vibes, built in.
|
|
173
|
+
</p>
|
|
174
|
+
</a>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
</main>
|
|
178
|
+
</div>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<nav class="docs-nav">
|
|
2
|
+
<div class="docs-nav-section">
|
|
3
|
+
<div class="docs-nav-title">Reactivity</div>
|
|
4
|
+
<a href="./signals.html" class="docs-nav-link">Signals</a>
|
|
5
|
+
<a href="./computed.html" class="docs-nav-link">Computed</a>
|
|
6
|
+
<a href="./effects.html" class="docs-nav-link">Effects</a>
|
|
7
|
+
<a href="./enhance.html" class="docs-nav-link">Enhance</a>
|
|
8
|
+
</div>
|
|
9
|
+
<div class="docs-nav-section">
|
|
10
|
+
<div class="docs-nav-title">Lightview X</div>
|
|
11
|
+
<a href="./state.html" class="docs-nav-link">State (Deep Reactivity)</a>
|
|
12
|
+
<a href="./hypermedia.html" class="docs-nav-link">Hypermedia</a>
|
|
13
|
+
<div class="docs-nav-section">
|
|
14
|
+
<div class="docs-nav-title">Elements</div>
|
|
15
|
+
<a href="./elements.html" class="docs-nav-link">Creating Elements</a>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</nav>
|