lego-dom 1.3.4 → 1.5.0
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/CHANGELOG.md +72 -1
- package/main.js +48 -17
- package/main.min.js +2 -2
- package/package.json +1 -1
- package/parse-lego.js +2 -2
- package/vite-plugin.js +0 -14
- package/.github/workflows/deploy-docs.yml +0 -56
- package/.legodom +0 -87
- package/docs/.vitepress/config.js +0 -161
- package/docs/api/config.md +0 -95
- package/docs/api/define.md +0 -58
- package/docs/api/directives.md +0 -50
- package/docs/api/globals.md +0 -29
- package/docs/api/index.md +0 -30
- package/docs/api/lifecycle.md +0 -40
- package/docs/api/route.md +0 -37
- package/docs/api/vite-plugin.md +0 -58
- package/docs/contributing/01-welcome.md +0 -38
- package/docs/contributing/02-registry.md +0 -133
- package/docs/contributing/03-batcher.md +0 -110
- package/docs/contributing/04-reactivity.md +0 -87
- package/docs/contributing/05-caching.md +0 -59
- package/docs/contributing/06-init.md +0 -136
- package/docs/contributing/07-observer.md +0 -72
- package/docs/contributing/08-snap.md +0 -140
- package/docs/contributing/09-diffing.md +0 -69
- package/docs/contributing/10-studs.md +0 -78
- package/docs/contributing/11-scanner.md +0 -117
- package/docs/contributing/12-render.md +0 -138
- package/docs/contributing/13-directives.md +0 -243
- package/docs/contributing/14-events.md +0 -57
- package/docs/contributing/15-router.md +0 -57
- package/docs/contributing/16-state.md +0 -47
- package/docs/contributing/17-legodom.md +0 -48
- package/docs/contributing/index.md +0 -24
- package/docs/examples/form.md +0 -42
- package/docs/examples/index.md +0 -104
- package/docs/examples/routing.md +0 -409
- package/docs/examples/sfc-showcase.md +0 -34
- package/docs/examples/todo-app.md +0 -383
- package/docs/guide/cdn-usage.md +0 -354
- package/docs/guide/components.md +0 -418
- package/docs/guide/directives.md +0 -539
- package/docs/guide/directory-structure.md +0 -248
- package/docs/guide/faq.md +0 -210
- package/docs/guide/getting-started.md +0 -262
- package/docs/guide/index.md +0 -88
- package/docs/guide/lifecycle.md +0 -525
- package/docs/guide/quick-start.md +0 -49
- package/docs/guide/reactivity.md +0 -415
- package/docs/guide/routing.md +0 -334
- package/docs/guide/server-side.md +0 -134
- package/docs/guide/sfc.md +0 -464
- package/docs/guide/templating.md +0 -388
- package/docs/index.md +0 -160
- package/docs/public/logo.svg +0 -17
- package/docs/router/basic-routing.md +0 -103
- package/docs/router/cold-entry.md +0 -91
- package/docs/router/history.md +0 -69
- package/docs/router/index.md +0 -73
- package/docs/router/resolver.md +0 -74
- package/docs/router/surgical-swaps.md +0 -134
- package/docs/tutorial/01-project-setup.md +0 -152
- package/docs/tutorial/02-your-first-component.md +0 -226
- package/docs/tutorial/03-adding-routes.md +0 -279
- package/docs/tutorial/04-multi-page-app.md +0 -329
- package/docs/tutorial/05-state-and-globals.md +0 -285
- package/docs/tutorial/index.md +0 -40
- package/examples/vite-app/README.md +0 -71
- package/examples/vite-app/index.html +0 -42
- package/examples/vite-app/package.json +0 -18
- package/examples/vite-app/src/app.css +0 -3
- package/examples/vite-app/src/app.js +0 -29
- package/examples/vite-app/src/components/app-navbar.lego +0 -34
- package/examples/vite-app/src/components/customers/customer-details.lego +0 -24
- package/examples/vite-app/src/components/customers/customer-orders.lego +0 -21
- package/examples/vite-app/src/components/customers/order-list.lego +0 -55
- package/examples/vite-app/src/components/greeting-card.lego +0 -41
- package/examples/vite-app/src/components/sample-component.lego +0 -75
- package/examples/vite-app/src/components/shells/customers-shell.lego +0 -21
- package/examples/vite-app/src/components/side-menu.lego +0 -46
- package/examples/vite-app/src/components/todo-list.lego +0 -239
- package/examples/vite-app/src/components/widgets/user-card.lego +0 -27
- package/examples/vite-app/vite.config.js +0 -22
- package/tests/error.test.js +0 -74
- package/tests/main.test.js +0 -103
- package/tests/memory.test.js +0 -68
- package/tests/monitoring.test.js +0 -74
- package/tests/naming.test.js +0 -74
- package/tests/parse-lego.test.js +0 -65
- package/tests/security.test.js +0 -67
- package/tests/server.test.js +0 -114
- package/tests/syntax.test.js +0 -67
package/docs/guide/cdn-usage.md
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
# CDN Usage
|
|
2
|
-
|
|
3
|
-
Lego works perfectly without any build tools. Just include it via CDN and start building!
|
|
4
|
-
|
|
5
|
-
## Quick Start
|
|
6
|
-
|
|
7
|
-
```html
|
|
8
|
-
<!DOCTYPE html>
|
|
9
|
-
<html>
|
|
10
|
-
<head>
|
|
11
|
-
<title>My App</title>
|
|
12
|
-
</head>
|
|
13
|
-
<body>
|
|
14
|
-
<!-- Define your component -->
|
|
15
|
-
<template b-id="hello-world">
|
|
16
|
-
<h1>[[ message ]]</h1>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<!-- Use it -->
|
|
20
|
-
<hello-world b-data="{ message: 'Hello from CDN!' }"></hello-world>
|
|
21
|
-
|
|
22
|
-
<!-- Include Lego -->
|
|
23
|
-
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
24
|
-
<script>
|
|
25
|
-
Lego.init();
|
|
26
|
-
</script>
|
|
27
|
-
</body>
|
|
28
|
-
</html>
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
That's it! Open this file in any browser and it works.
|
|
32
|
-
|
|
33
|
-
## CDN Providers
|
|
34
|
-
|
|
35
|
-
### unpkg (Recommended)
|
|
36
|
-
|
|
37
|
-
```html
|
|
38
|
-
<!-- Latest version -->
|
|
39
|
-
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
40
|
-
|
|
41
|
-
<!-- Specific version -->
|
|
42
|
-
<script src="https://unpkg.com/lego-dom@1.3.4/main.js"></script>
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### jsdelivr
|
|
46
|
-
|
|
47
|
-
```html
|
|
48
|
-
<!-- Latest version -->
|
|
49
|
-
<script src="https://cdn.jsdelivr.net/npm/lego-dom/main.js"></script>
|
|
50
|
-
|
|
51
|
-
<!-- Specific version -->
|
|
52
|
-
<script src="https://cdn.jsdelivr.net/npm/lego-dom@1.3.4/main.js"></script>
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## Complete Example
|
|
58
|
-
|
|
59
|
-
Here's a full working application using only CDN:
|
|
60
|
-
|
|
61
|
-
```html
|
|
62
|
-
<!DOCTYPE html>
|
|
63
|
-
<html lang="en">
|
|
64
|
-
<head>
|
|
65
|
-
<meta charset="UTF-8">
|
|
66
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
67
|
-
<title>Todo App - Lego</title>
|
|
68
|
-
<style>
|
|
69
|
-
body {
|
|
70
|
-
font-family: system-ui, sans-serif;
|
|
71
|
-
max-width: 600px;
|
|
72
|
-
margin: 2rem auto;
|
|
73
|
-
padding: 0 1rem;
|
|
74
|
-
}
|
|
75
|
-
</style>
|
|
76
|
-
</head>
|
|
77
|
-
<body>
|
|
78
|
-
<h1>My Todo App</h1>
|
|
79
|
-
<todo-app></todo-app>
|
|
80
|
-
|
|
81
|
-
<template b-id="todo-app">
|
|
82
|
-
<style>
|
|
83
|
-
self {
|
|
84
|
-
display: block;
|
|
85
|
-
}
|
|
86
|
-
.input-group {
|
|
87
|
-
display: flex;
|
|
88
|
-
gap: 0.5rem;
|
|
89
|
-
margin-bottom: 1rem;
|
|
90
|
-
}
|
|
91
|
-
input {
|
|
92
|
-
flex: 1;
|
|
93
|
-
padding: 0.5rem;
|
|
94
|
-
font-size: 1rem;
|
|
95
|
-
}
|
|
96
|
-
button {
|
|
97
|
-
padding: 0.5rem 1rem;
|
|
98
|
-
font-size: 1rem;
|
|
99
|
-
background: #4CAF50;
|
|
100
|
-
color: white;
|
|
101
|
-
border: none;
|
|
102
|
-
cursor: pointer;
|
|
103
|
-
}
|
|
104
|
-
ul {
|
|
105
|
-
list-style: none;
|
|
106
|
-
padding: 0;
|
|
107
|
-
}
|
|
108
|
-
li {
|
|
109
|
-
padding: 0.75rem;
|
|
110
|
-
border-bottom: 1px solid #eee;
|
|
111
|
-
display: flex;
|
|
112
|
-
align-items: center;
|
|
113
|
-
gap: 0.5rem;
|
|
114
|
-
}
|
|
115
|
-
.done {
|
|
116
|
-
text-decoration: line-through;
|
|
117
|
-
opacity: 0.6;
|
|
118
|
-
}
|
|
119
|
-
</style>
|
|
120
|
-
|
|
121
|
-
<div class="input-group">
|
|
122
|
-
<input
|
|
123
|
-
b-sync="newTodo"
|
|
124
|
-
placeholder="What needs to be done?"
|
|
125
|
-
@keyup="event.key === 'Enter' && addTodo()">
|
|
126
|
-
<button @click="addTodo()">Add</button>
|
|
127
|
-
</div>
|
|
128
|
-
|
|
129
|
-
<ul>
|
|
130
|
-
<li b-for="todo in todos">
|
|
131
|
-
<input type="checkbox" b-sync="todo.done">
|
|
132
|
-
<span class="[[ todo.done ? 'done' : '' ]]">
|
|
133
|
-
[[ todo.text ]]
|
|
134
|
-
</span>
|
|
135
|
-
</li>
|
|
136
|
-
</ul>
|
|
137
|
-
|
|
138
|
-
<p>[[ remaining() ]] remaining</p>
|
|
139
|
-
</template>
|
|
140
|
-
|
|
141
|
-
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
142
|
-
|
|
143
|
-
<script>
|
|
144
|
-
// Initialize with data
|
|
145
|
-
Lego.define('todo-app', Lego.registry['todo-app'].innerHTML, {
|
|
146
|
-
newTodo: '',
|
|
147
|
-
todos: [
|
|
148
|
-
{ text: 'Learn Lego', done: true },
|
|
149
|
-
{ text: 'Build something awesome', done: false }
|
|
150
|
-
],
|
|
151
|
-
addTodo() {
|
|
152
|
-
if (this.newTodo.trim()) {
|
|
153
|
-
this.todos.push({
|
|
154
|
-
text: this.newTodo,
|
|
155
|
-
done: false
|
|
156
|
-
});
|
|
157
|
-
this.newTodo = '';
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
remaining() {
|
|
161
|
-
return this.todos.filter(t => !t.done).length;
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// Don't forget to init!
|
|
166
|
-
Lego.init();
|
|
167
|
-
</script>
|
|
168
|
-
</body>
|
|
169
|
-
</html>
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
## Progressive Enhancement
|
|
173
|
-
|
|
174
|
-
Lego is perfect for progressively enhancing existing sites:
|
|
175
|
-
|
|
176
|
-
```html
|
|
177
|
-
<!-- Your existing page -->
|
|
178
|
-
<div id="legacy-content">
|
|
179
|
-
<h1>My Existing Site</h1>
|
|
180
|
-
<p>This works without JavaScript</p>
|
|
181
|
-
</div>
|
|
182
|
-
|
|
183
|
-
<!-- Add interactive components -->
|
|
184
|
-
<user-widget></user-widget>
|
|
185
|
-
|
|
186
|
-
<template b-id="user-widget">
|
|
187
|
-
<style>
|
|
188
|
-
self {
|
|
189
|
-
position: fixed;
|
|
190
|
-
bottom: 1rem;
|
|
191
|
-
right: 1rem;
|
|
192
|
-
background: white;
|
|
193
|
-
padding: 1rem;
|
|
194
|
-
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
195
|
-
}
|
|
196
|
-
</style>
|
|
197
|
-
<p>Welcome, [[ username ]]!</p>
|
|
198
|
-
<button @click="logout()">Logout</button>
|
|
199
|
-
</template>
|
|
200
|
-
|
|
201
|
-
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
202
|
-
<script>
|
|
203
|
-
Lego.define('user-widget', Lego.registry['user-widget'].innerHTML, {
|
|
204
|
-
username: 'Guest',
|
|
205
|
-
async mounted() {
|
|
206
|
-
const user = await fetch('/api/user').then(r => r.json());
|
|
207
|
-
this.username = user.name;
|
|
208
|
-
},
|
|
209
|
-
logout() {
|
|
210
|
-
window.location.href = '/logout';
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
Lego.init();
|
|
215
|
-
</script>
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
## Embedding in Existing Apps
|
|
219
|
-
|
|
220
|
-
Lego components work alongside other frameworks:
|
|
221
|
-
|
|
222
|
-
```html
|
|
223
|
-
<!-- Works fine with jQuery, Bootstrap, etc. -->
|
|
224
|
-
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
225
|
-
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
226
|
-
|
|
227
|
-
<!-- Your Lego component -->
|
|
228
|
-
<my-component></my-component>
|
|
229
|
-
|
|
230
|
-
<!-- Your jQuery code -->
|
|
231
|
-
<script>
|
|
232
|
-
$(document).ready(function() {
|
|
233
|
-
// jQuery code here
|
|
234
|
-
});
|
|
235
|
-
</script>
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
## Loading Strategy
|
|
239
|
-
|
|
240
|
-
### For Production
|
|
241
|
-
|
|
242
|
-
Always pin to a specific version:
|
|
243
|
-
|
|
244
|
-
```html
|
|
245
|
-
<script src="https://unpkg.com/lego-dom@1.3.4/main.js"></script>
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
### For Development/Prototyping
|
|
249
|
-
|
|
250
|
-
Use latest:
|
|
251
|
-
|
|
252
|
-
```html
|
|
253
|
-
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
### With defer
|
|
257
|
-
|
|
258
|
-
Load asynchronously without blocking page render:
|
|
259
|
-
|
|
260
|
-
```html
|
|
261
|
-
<script defer src="https://unpkg.com/lego-dom/main.js"></script>
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### With integrity (SRI)
|
|
265
|
-
|
|
266
|
-
For maximum security:
|
|
267
|
-
|
|
268
|
-
```html
|
|
269
|
-
<script
|
|
270
|
-
src="https://unpkg.com/lego-dom@1.3.4/main.js"
|
|
271
|
-
integrity="sha384-..."
|
|
272
|
-
crossorigin="anonymous">
|
|
273
|
-
</script>
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
## Browser Compatibility
|
|
277
|
-
|
|
278
|
-
Lego works in all modern browsers:
|
|
279
|
-
|
|
280
|
-
- ✅ Chrome 63+
|
|
281
|
-
- ✅ Firefox 63+
|
|
282
|
-
- ✅ Safari 11.1+
|
|
283
|
-
- ✅ Edge 79+
|
|
284
|
-
|
|
285
|
-
No polyfills needed for these browsers!
|
|
286
|
-
|
|
287
|
-
## Using .lego Files without Build Tools
|
|
288
|
-
|
|
289
|
-
You can use full Single File Components (`.lego` files) directly in the browser without any build step!
|
|
290
|
-
Lego provides a `loader` configuration that lets you fetch component files on demand.
|
|
291
|
-
|
|
292
|
-
### How it Works
|
|
293
|
-
|
|
294
|
-
1. **Serve your files**: Make sure your `.lego` files are accessible via HTTP (e.g., in a `/components` folder).
|
|
295
|
-
2. **Configure the loader**: Tell Lego how to fetch a component when it encounters an unknown tag.
|
|
296
|
-
|
|
297
|
-
### Example
|
|
298
|
-
|
|
299
|
-
```html
|
|
300
|
-
<script>
|
|
301
|
-
Lego.init(document.body, {
|
|
302
|
-
// The loader function receives the tag name (e.g., 'user-card')
|
|
303
|
-
// and must return a Promise that resolves to the component's source code.
|
|
304
|
-
loader: (tagName) => {
|
|
305
|
-
// Fetch the raw text content of the .lego file
|
|
306
|
-
return fetch(`/components/${tagName}.lego`).then(res => res.text());
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
</script>
|
|
310
|
-
|
|
311
|
-
<!-- Now just use the tag! Lego will fetch, compile, and render it automatically. -->
|
|
312
|
-
<user-card></user-card>
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
This is perfect for:
|
|
316
|
-
- **Micro-frontends**: Load components from different services.
|
|
317
|
-
- **CMS Integration**: Store component code in a database.
|
|
318
|
-
- **Dynamic Apps**: Load features only when they are needed.
|
|
319
|
-
|
|
320
|
-
## Pros and Cons
|
|
321
|
-
|
|
322
|
-
### Advantages
|
|
323
|
-
|
|
324
|
-
- **No build step** - Instant development
|
|
325
|
-
- **No npm** - No dependency management
|
|
326
|
-
- **Fast prototyping** - Perfect for demos and learning
|
|
327
|
-
- **Progressive enhancement** - Add to existing sites easily
|
|
328
|
-
- **Low barrier** - Great for beginners
|
|
329
|
-
|
|
330
|
-
### Limitations
|
|
331
|
-
|
|
332
|
-
- No hot module replacement
|
|
333
|
-
- Slower for large apps compared to bundled versions
|
|
334
|
-
|
|
335
|
-
## When to Use CDN
|
|
336
|
-
|
|
337
|
-
**Perfect for:**
|
|
338
|
-
- Prototypes and demos
|
|
339
|
-
- Small websites (1-5 components)
|
|
340
|
-
- Progressive enhancement
|
|
341
|
-
- Learning and experimentation
|
|
342
|
-
- CodePen/JSFiddle examples
|
|
343
|
-
|
|
344
|
-
**Consider bundling for:**
|
|
345
|
-
- Large applications (10+ components)
|
|
346
|
-
- Production apps requiring optimization
|
|
347
|
-
- Projects needing TypeScript
|
|
348
|
-
- Teams wanting SFC workflow
|
|
349
|
-
|
|
350
|
-
## Next Steps
|
|
351
|
-
|
|
352
|
-
- See [complete CDN examples](/examples/)
|
|
353
|
-
- Learn about [routing](/guide/routing) for multi-page apps
|
|
354
|
-
- Explore [directives](/guide/directives) for common patterns
|