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.
Files changed (93) hide show
  1. package/CHANGELOG.md +72 -1
  2. package/main.js +48 -17
  3. package/main.min.js +2 -2
  4. package/package.json +1 -1
  5. package/parse-lego.js +2 -2
  6. package/vite-plugin.js +0 -14
  7. package/.github/workflows/deploy-docs.yml +0 -56
  8. package/.legodom +0 -87
  9. package/docs/.vitepress/config.js +0 -161
  10. package/docs/api/config.md +0 -95
  11. package/docs/api/define.md +0 -58
  12. package/docs/api/directives.md +0 -50
  13. package/docs/api/globals.md +0 -29
  14. package/docs/api/index.md +0 -30
  15. package/docs/api/lifecycle.md +0 -40
  16. package/docs/api/route.md +0 -37
  17. package/docs/api/vite-plugin.md +0 -58
  18. package/docs/contributing/01-welcome.md +0 -38
  19. package/docs/contributing/02-registry.md +0 -133
  20. package/docs/contributing/03-batcher.md +0 -110
  21. package/docs/contributing/04-reactivity.md +0 -87
  22. package/docs/contributing/05-caching.md +0 -59
  23. package/docs/contributing/06-init.md +0 -136
  24. package/docs/contributing/07-observer.md +0 -72
  25. package/docs/contributing/08-snap.md +0 -140
  26. package/docs/contributing/09-diffing.md +0 -69
  27. package/docs/contributing/10-studs.md +0 -78
  28. package/docs/contributing/11-scanner.md +0 -117
  29. package/docs/contributing/12-render.md +0 -138
  30. package/docs/contributing/13-directives.md +0 -243
  31. package/docs/contributing/14-events.md +0 -57
  32. package/docs/contributing/15-router.md +0 -57
  33. package/docs/contributing/16-state.md +0 -47
  34. package/docs/contributing/17-legodom.md +0 -48
  35. package/docs/contributing/index.md +0 -24
  36. package/docs/examples/form.md +0 -42
  37. package/docs/examples/index.md +0 -104
  38. package/docs/examples/routing.md +0 -409
  39. package/docs/examples/sfc-showcase.md +0 -34
  40. package/docs/examples/todo-app.md +0 -383
  41. package/docs/guide/cdn-usage.md +0 -354
  42. package/docs/guide/components.md +0 -418
  43. package/docs/guide/directives.md +0 -539
  44. package/docs/guide/directory-structure.md +0 -248
  45. package/docs/guide/faq.md +0 -210
  46. package/docs/guide/getting-started.md +0 -262
  47. package/docs/guide/index.md +0 -88
  48. package/docs/guide/lifecycle.md +0 -525
  49. package/docs/guide/quick-start.md +0 -49
  50. package/docs/guide/reactivity.md +0 -415
  51. package/docs/guide/routing.md +0 -334
  52. package/docs/guide/server-side.md +0 -134
  53. package/docs/guide/sfc.md +0 -464
  54. package/docs/guide/templating.md +0 -388
  55. package/docs/index.md +0 -160
  56. package/docs/public/logo.svg +0 -17
  57. package/docs/router/basic-routing.md +0 -103
  58. package/docs/router/cold-entry.md +0 -91
  59. package/docs/router/history.md +0 -69
  60. package/docs/router/index.md +0 -73
  61. package/docs/router/resolver.md +0 -74
  62. package/docs/router/surgical-swaps.md +0 -134
  63. package/docs/tutorial/01-project-setup.md +0 -152
  64. package/docs/tutorial/02-your-first-component.md +0 -226
  65. package/docs/tutorial/03-adding-routes.md +0 -279
  66. package/docs/tutorial/04-multi-page-app.md +0 -329
  67. package/docs/tutorial/05-state-and-globals.md +0 -285
  68. package/docs/tutorial/index.md +0 -40
  69. package/examples/vite-app/README.md +0 -71
  70. package/examples/vite-app/index.html +0 -42
  71. package/examples/vite-app/package.json +0 -18
  72. package/examples/vite-app/src/app.css +0 -3
  73. package/examples/vite-app/src/app.js +0 -29
  74. package/examples/vite-app/src/components/app-navbar.lego +0 -34
  75. package/examples/vite-app/src/components/customers/customer-details.lego +0 -24
  76. package/examples/vite-app/src/components/customers/customer-orders.lego +0 -21
  77. package/examples/vite-app/src/components/customers/order-list.lego +0 -55
  78. package/examples/vite-app/src/components/greeting-card.lego +0 -41
  79. package/examples/vite-app/src/components/sample-component.lego +0 -75
  80. package/examples/vite-app/src/components/shells/customers-shell.lego +0 -21
  81. package/examples/vite-app/src/components/side-menu.lego +0 -46
  82. package/examples/vite-app/src/components/todo-list.lego +0 -239
  83. package/examples/vite-app/src/components/widgets/user-card.lego +0 -27
  84. package/examples/vite-app/vite.config.js +0 -22
  85. package/tests/error.test.js +0 -74
  86. package/tests/main.test.js +0 -103
  87. package/tests/memory.test.js +0 -68
  88. package/tests/monitoring.test.js +0 -74
  89. package/tests/naming.test.js +0 -74
  90. package/tests/parse-lego.test.js +0 -65
  91. package/tests/security.test.js +0 -67
  92. package/tests/server.test.js +0 -114
  93. package/tests/syntax.test.js +0 -67
package/docs/guide/sfc.md DELETED
@@ -1,464 +0,0 @@
1
- # Single File Components (.lego)
2
-
3
- Single File Components (SFCs) let you define components in dedicated `.lego` files when using Vite as your build tool.
4
-
5
- ::: tip πŸš€ New to LegoDOM?
6
- Start with our **[Step-by-Step Tutorial](/tutorial/)** to build a complete multi-page app with SFCs!
7
- :::
8
-
9
- ## Where Does My Config Go?
10
-
11
- The #1 question developers ask: **"I have a `.lego` file – now where do I put my routes?"**
12
-
13
- **Answer: Everything goes in your entry file (`app.js` or `main.js`):**
14
-
15
- ```javascript
16
- // src/app.js – The control center of your app
17
-
18
- import { Lego } from 'lego-dom';
19
- import registerComponents from 'virtual:lego-components';
20
-
21
- // 1. Register all .lego files automatically
22
- registerComponents();
23
-
24
- // 2. Define your routes
25
- Lego.route('/', 'home-page'); // home-page.lego
26
- Lego.route('/login', 'login-page'); // login-page.lego
27
- Lego.route('/users/:id', 'user-profile'); // user-profile.lego
28
-
29
- // 3. Initialize global state (optional)
30
- Lego.globals.user = null;
31
-
32
- // 4. Start the engine
33
- await Lego.init();
34
- ```
35
-
36
- Your `index.html` just needs:
37
- ```html
38
- <lego-router></lego-router>
39
- <script type="module" src="/src/app.js"></script>
40
- ```
41
-
42
- That's the complete pattern! πŸŽ‰
43
-
44
- ---
45
-
46
- ## Why SFCs?
47
-
48
- When your project grows, keeping components in separate files makes your codebase more organized and maintainable.
49
-
50
- ### Benefits
51
-
52
- βœ… **Better Organization** - One file per component
53
- βœ… **Syntax Highlighting** - Proper editor support
54
- βœ… **Auto-discovery** - Vite plugin finds and registers components automatically
55
- βœ… **Hot Reload** - Changes reflect instantly during development
56
- βœ… **Familiar Format** - Similar to Vue SFCs if you've used them
57
-
58
- ## File Format
59
-
60
- A `.lego` file contains three optional sections:
61
-
62
- ```html
63
- <template>
64
- <!-- Your component markup -->
65
- </template>
66
-
67
- <script>
68
- // Your component logic
69
- export default {
70
- // reactive state and methods
71
- }
72
- </script>
73
-
74
- <style>
75
- /* Scoped styles */
76
- </style>
77
- ```
78
-
79
- ### Example Component
80
-
81
- Here's a complete example (`user-card.lego`):
82
-
83
- ```html
84
- <template>
85
- <img class="avatar" src="[[ avatarUrl ]]" alt="[[ name ]]">
86
- <h2 class="name">[[ name ]]</h2>
87
- <p class="bio">[[ bio ]]</p>
88
- <p>Followers: [[ followers ]]</p>
89
- <button @click="follow()">
90
- [[ isFollowing ? 'Unfollow' : 'Follow' ]]
91
- </button>
92
- </template>
93
-
94
- <style>
95
- self {
96
- display: block;
97
- padding: 1.5rem;
98
- border: 2px solid #ddd;
99
- border-radius: 8px;
100
- max-width: 300px;
101
- }
102
-
103
- .avatar {
104
- width: 80px;
105
- height: 80px;
106
- border-radius: 50%;
107
- object-fit: cover;
108
- }
109
-
110
- .name {
111
- font-size: 1.5rem;
112
- font-weight: bold;
113
- margin: 0.5rem 0;
114
- }
115
-
116
- .bio {
117
- color: #666;
118
- margin: 0.5rem 0;
119
- }
120
-
121
- button {
122
- background: #4CAF50;
123
- color: white;
124
- border: none;
125
- padding: 0.5rem 1rem;
126
- border-radius: 4px;
127
- cursor: pointer;
128
- }
129
- </style>
130
-
131
- <script>
132
- export default {
133
- name: 'John Doe',
134
- bio: 'Web developer & coffee enthusiast',
135
- avatarUrl: 'https://api.dicebear.com/7.x/avataaars/svg?seed=John',
136
- followers: 1234,
137
- isFollowing: false,
138
-
139
- follow() {
140
- if (this.isFollowing) {
141
- this.followers--;
142
- this.isFollowing = false;
143
- } else {
144
- this.followers++;
145
- this.isFollowing = true;
146
- }
147
- }
148
- }
149
- </script>
150
- ```
151
-
152
- ## Vite Plugin Setup
153
-
154
- ### Installation
155
-
156
- ```bash
157
- npm install -D vite lego-dom
158
- ```
159
-
160
- ### Configuration
161
-
162
- Create or update `vite.config.js`:
163
-
164
- ```js
165
- import { defineConfig } from 'vite';
166
- import legoPlugin from 'lego-dom/vite-plugin';
167
-
168
- export default defineConfig({
169
- plugins: [
170
- legoPlugin({
171
- componentsDir: './src/components', // Where to look
172
- include: ['**/*.lego'] // What to match
173
- })
174
- ]
175
- });
176
- ```
177
-
178
- ### Project Structure
179
-
180
- ```
181
- my-app/
182
- β”œβ”€β”€ src/
183
- β”‚ β”œβ”€β”€ components/
184
- β”‚ β”‚ β”œβ”€β”€ user-card.lego
185
- β”‚ β”‚ β”œβ”€β”€ post-list.lego
186
- β”‚ β”‚ └── comment-item.lego
187
- β”‚ └── main.js
188
- β”œβ”€β”€ index.html
189
- β”œβ”€β”€ package.json
190
- └── vite.config.js
191
- ```
192
-
193
- ### Entry Point
194
-
195
- In your `src/main.js`:
196
-
197
- ```js
198
- import { Lego } from 'lego-dom/main.js';
199
- import registerComponents from 'virtual:lego-components';
200
-
201
- // Auto-register all discovered components
202
- registerComponents();
203
-
204
- // Now all .lego components are available!
205
- ```
206
-
207
- ### Use Components
208
-
209
- In your `index.html`:
210
-
211
- ```html
212
- <!DOCTYPE html>
213
- <html>
214
- <head>
215
- <title>My Lego App</title>
216
- </head>
217
- <body>
218
- <div id="app">
219
- <user-card></user-card>
220
- <post-list></post-list>
221
- </div>
222
-
223
- <script type="module" src="/src/main.js"></script>
224
- </body>
225
- </html>
226
- ```
227
-
228
- ## Component Naming
229
-
230
- Component names are automatically derived from filenames:
231
-
232
- | Filename | Component Tag |
233
- |----------|--------------|
234
- | `user-card.lego` | `<user-card>` |
235
- | `post-list.lego` | `<post-list>` |
236
- | `comment-item.lego` | `<comment-item>` |
237
-
238
- ::: warning Naming Rules
239
- Component names **must**:
240
- - Be kebab-case (lowercase with hyphens)
241
- - Contain at least one hyphen
242
- - Match the pattern: `[a-z][a-z0-9]*(-[a-z0-9]+)+`
243
-
244
- βœ… Good: `user-card`, `post-list`, `nav-menu`
245
- ❌ Bad: `UserCard`, `postlist`, `card`
246
- :::
247
-
248
- ## Section Details
249
-
250
- ### Template Section
251
-
252
- Contains your component's HTML markup with Lego directives:
253
-
254
- ```html
255
- <template>
256
- <h1>[[ title ]]</h1>
257
- <p b-show="showContent">[[ content ]]</p>
258
- <ul>
259
- <li b-for="item in items">[[ item ]]</li>
260
- </ul>
261
- </template>
262
- ```
263
-
264
- ### Script Section
265
-
266
- Exports the component's reactive state and methods:
267
-
268
- ```html
269
- <script>
270
- export default {
271
- // Reactive properties
272
- title: 'Welcome',
273
- count: 0,
274
- items: ['apple', 'banana'],
275
-
276
- // Methods
277
- increment() {
278
- this.count++;
279
- },
280
-
281
- // Lifecycle hooks
282
- mounted() {
283
- console.log('Component mounted!');
284
- }
285
- }
286
- </script>
287
- ```
288
-
289
- ### Style Section
290
-
291
- Scoped styles using Shadow DOM. Use `self` to target the component root:
292
-
293
- ```html
294
- <style>
295
- self {
296
- display: block;
297
- padding: 1rem;
298
- }
299
-
300
- h1 {
301
- color: #333;
302
- }
303
-
304
- button {
305
- background: blue;
306
- color: white;
307
- }
308
- </style>
309
- ```
310
-
311
- Styles are automatically scoped to your componentβ€”they won't affect other components or global styles.
312
-
313
- ## Dynamic Styles
314
-
315
- A powerful feature of LegoDOM SFCs is that **interpolation works inside `<style>` tags too!**
316
-
317
- You can use `[[ ]]` to bind CSS values directly to your component's state, props, or logic. Because styles are scoped (Shadow DOM), this is safe and won't leak.
318
-
319
- ```html
320
- <template>
321
- <button @click="toggleTheme()">Toggle Theme</button>
322
- </template>
323
-
324
- <style>
325
- /* Use state variables directly in CSS */
326
- self {
327
- background-color: [[ theme === 'dark' ? '#333' : '#fff' ]];
328
- color: [[ theme === 'dark' ? '#fff' : '#000' ]];
329
-
330
- /* You can also bind strict values for calculation */
331
- --padding: [[ basePadding + 'px' ]];
332
- padding: var(--padding);
333
- }
334
- </style>
335
-
336
- <script>
337
- export default {
338
- theme: 'light',
339
- basePadding: 20,
340
-
341
- toggleTheme() {
342
- this.theme = this.theme === 'light' ? 'dark' : 'light';
343
- }
344
- }
345
- </script>
346
- ```
347
-
348
- ::: tip Why this rocks 🀘
349
- This eliminates the need for CSS-in-JS libraries. You get full reactivity in your CSS with standard syntax.
350
- :::
351
-
352
- ::: warning Performance Note
353
- Binding to CSS properties works great for themes, settings, and layout changes.
354
- For high-frequency updates (like drag-and-drop coordinates or 60fps animations), prefer binding to **CSS Variables** on the host element (`style="--x: [[ x ]]"`) to avoid re-parsing the stylesheet on every frame.
355
- :::
356
-
357
- ## Hot Module Replacement
358
-
359
- During development, changes to `.lego` files trigger a full page reload. Your changes appear instantly!
360
-
361
- ```bash
362
- npm run dev
363
- ```
364
-
365
- Edit your component, save, and see the result immediately.
366
-
367
- ## Passing Props
368
-
369
- Pass data to components via the `b-data` attribute:
370
-
371
- ```html
372
- <user-card b-data="{
373
- name: 'Jane Smith',
374
- bio: 'Designer',
375
- followers: 5678
376
- }"></user-card>
377
- ```
378
-
379
- Or define defaults in the script section and override as needed.
380
-
381
- ## Best Practices
382
-
383
- ### 1. Keep Components Small
384
-
385
- Each `.lego` file should represent a single, focused component.
386
-
387
- βœ… Good: `user-avatar.lego`, `user-name.lego`, `user-bio.lego`
388
- ❌ Bad: `entire-profile-page.lego`
389
-
390
- ### 2. Use Semantic Names
391
-
392
- Name components after what they represent, not how they look:
393
-
394
- βœ… Good: `article-preview.lego`, `comment-list.lego`
395
- ❌ Bad: `blue-box.lego`, `flex-container.lego`
396
-
397
- ### 3. Organize by Feature
398
-
399
- ```
400
- components/
401
- β”œβ”€β”€ user/
402
- β”‚ β”œβ”€β”€ user-card.lego
403
- β”‚ β”œβ”€β”€ user-avatar.lego
404
- β”‚ └── user-profile.lego
405
- β”œβ”€β”€ posts/
406
- β”‚ β”œβ”€β”€ post-item.lego
407
- β”‚ └── post-list.lego
408
- └── shared/
409
- β”œβ”€β”€ app-button.lego
410
- └── app-modal.lego
411
- ```
412
-
413
- ## Limitations
414
-
415
- - `.lego` files require Viteβ€”they don't work with direct `<script>` tag inclusion
416
- - Each file creates exactly one component
417
- - Component name is derived from filename (cannot be customized)
418
-
419
- ## Comparison: SFC vs Traditional
420
-
421
- ### Traditional (HTML Template)
422
-
423
- ```html
424
- <template b-id="my-component">
425
- <style>self { padding: 1rem; }</style>
426
- <h1>[[ title ]]</h1>
427
- </template>
428
-
429
- <my-component b-data="{ title: 'Hello' }"></my-component>
430
- ```
431
-
432
- ### SFC (.lego file)
433
-
434
- ```html
435
- <!-- my-component.lego -->
436
- <template>
437
- <h1>[[ title ]]</h1>
438
- </template>
439
-
440
- <style>
441
- self { padding: 1rem; }
442
- </style>
443
-
444
- <script>
445
- export default {
446
- title: 'Hello'
447
- }
448
- </script>
449
- ```
450
-
451
- ```html
452
- <!-- index.html -->
453
- <my-component></my-component>
454
- ```
455
-
456
- Both work perfectly! Choose based on your project needs:
457
- - **Small projects / prototypes** β†’ HTML templates
458
- - **Medium/large projects** β†’ SFCs with Vite
459
-
460
- ## Next Steps
461
-
462
- - See [complete SFC examples](/examples/sfc-showcase)
463
- - Learn about the [Vite plugin API](/api/vite-plugin)
464
- - Check out the [routing guide](/guide/routing) for building apps