lego-dom 0.0.9 → 1.0.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 +44 -0
- package/README.md +1 -0
- package/{go.html → cdn.html} +33 -26
- package/docs/.vitepress/config.js +39 -1
- package/docs/api/directives.md +3 -3
- package/docs/api/index.md +1 -1
- package/docs/contributing/01-welcome.md +36 -0
- package/docs/contributing/02-registry.md +99 -0
- package/docs/contributing/03-batcher.md +110 -0
- package/docs/contributing/04-reactivity.md +87 -0
- package/docs/contributing/05-caching.md +59 -0
- package/docs/contributing/06-init.md +125 -0
- package/docs/contributing/07-observer.md +69 -0
- package/docs/contributing/08-snap.md +126 -0
- package/docs/contributing/09-diffing.md +69 -0
- package/docs/contributing/10-studs.md +76 -0
- package/docs/contributing/11-scanner.md +104 -0
- package/docs/contributing/12-render.md +116 -0
- package/docs/contributing/13-directives.md +225 -0
- package/docs/contributing/14-events.md +57 -0
- package/docs/contributing/15-router.md +9 -0
- package/docs/contributing/16-state.md +48 -0
- package/docs/contributing/17-legodom.md +55 -0
- package/docs/contributing/index.md +5 -0
- package/docs/examples/form.md +1 -1
- package/docs/examples/index.md +1 -1
- package/docs/examples/routing.md +4 -4
- package/docs/examples/todo-app.md +1 -1
- package/docs/guide/cdn-usage.md +8 -0
- package/docs/guide/components.md +33 -15
- package/docs/guide/directives.md +22 -22
- package/docs/guide/getting-started.md +35 -10
- package/docs/guide/index.md +3 -3
- package/docs/guide/quick-start.md +4 -1
- package/docs/guide/reactivity.md +22 -1
- package/docs/guide/routing.md +189 -289
- package/docs/guide/sfc.md +1 -1
- package/docs/guide/templating.md +2 -2
- package/docs/index.md +41 -7
- package/docs/router/basic-routing.md +103 -0
- package/docs/router/cold-entry.md +91 -0
- package/docs/router/history.md +69 -0
- package/docs/router/index.md +73 -0
- package/docs/router/resolver.md +74 -0
- package/docs/router/surgical-swaps.md +134 -0
- package/examples/vite-app/index.html +4 -12
- package/examples/vite-app/package.json +4 -2
- package/examples/vite-app/src/app.css +3 -0
- package/examples/vite-app/src/app.js +29 -0
- package/examples/vite-app/src/components/app-navbar.lego +34 -0
- package/examples/vite-app/src/components/customers/customer-details.lego +24 -0
- package/examples/vite-app/src/components/customers/customer-orders.lego +21 -0
- package/examples/vite-app/src/components/customers/order-list.lego +55 -0
- package/examples/vite-app/src/components/greeting-card.lego +1 -1
- package/examples/vite-app/src/components/sample-component.lego +15 -15
- package/examples/vite-app/src/components/shells/customers-shell.lego +21 -0
- package/examples/vite-app/src/components/todo-list.lego +12 -15
- package/examples/vite-app/src/components/widgets/user-card.lego +27 -0
- package/examples/vite-app/vite.config.js +5 -1
- package/main.js +247 -56
- package/package.json +1 -1
- package/parse-lego.js +17 -8
- package/{main.test.js → tests/main.test.js} +34 -17
- package/tests/parse-lego.test.js +65 -0
- package/vite-plugin.js +60 -22
- package/docs/.vitepress/dist/404.html +0 -22
- package/docs/.vitepress/dist/api/define.html +0 -35
- package/docs/.vitepress/dist/api/directives.html +0 -32
- package/docs/.vitepress/dist/api/globals.html +0 -27
- package/docs/.vitepress/dist/api/index.html +0 -25
- package/docs/.vitepress/dist/api/lifecycle.html +0 -38
- package/docs/.vitepress/dist/api/route.html +0 -34
- package/docs/.vitepress/dist/api/vite-plugin.html +0 -37
- package/docs/.vitepress/dist/assets/api_define.md.UA-ygUnQ.js +0 -11
- package/docs/.vitepress/dist/assets/api_define.md.UA-ygUnQ.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_directives.md.BV-D251p.js +0 -8
- package/docs/.vitepress/dist/assets/api_directives.md.BV-D251p.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_globals.md.CEznyRAY.js +0 -3
- package/docs/.vitepress/dist/assets/api_globals.md.CEznyRAY.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_index.md.IEYUxUIr.js +0 -1
- package/docs/.vitepress/dist/assets/api_index.md.IEYUxUIr.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_lifecycle.md.Ccm5xw6-.js +0 -14
- package/docs/.vitepress/dist/assets/api_lifecycle.md.Ccm5xw6-.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_route.md.CAHf_KNp.js +0 -10
- package/docs/.vitepress/dist/assets/api_route.md.CAHf_KNp.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_vite-plugin.md.DC8Li09k.js +0 -13
- package/docs/.vitepress/dist/assets/api_vite-plugin.md.DC8Li09k.lean.js +0 -1
- package/docs/.vitepress/dist/assets/app.BfblNDJy.js +0 -1
- package/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.Crdp7-Zp.js +0 -1
- package/docs/.vitepress/dist/assets/chunks/VPLocalSearchBox.C18E44rY.js +0 -9
- package/docs/.vitepress/dist/assets/chunks/framework.B7OFBR9X.js +0 -19
- package/docs/.vitepress/dist/assets/chunks/theme.VX3itTW6.js +0 -2
- package/docs/.vitepress/dist/assets/examples_form.md.DQoAgbLR.js +0 -34
- package/docs/.vitepress/dist/assets/examples_form.md.DQoAgbLR.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_index.md.CVJJjXXE.js +0 -28
- package/docs/.vitepress/dist/assets/examples_index.md.CVJJjXXE.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_routing.md.sRnA5RXw.js +0 -338
- package/docs/.vitepress/dist/assets/examples_routing.md.sRnA5RXw.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_sfc-showcase.md.DPf9Wm99.js +0 -13
- package/docs/.vitepress/dist/assets/examples_sfc-showcase.md.DPf9Wm99.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_todo-app.md.CqF4JaWn.js +0 -297
- package/docs/.vitepress/dist/assets/examples_todo-app.md.CqF4JaWn.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_cdn-usage.md.CjIjusre.js +0 -182
- package/docs/.vitepress/dist/assets/guide_cdn-usage.md.CjIjusre.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_components.md.CMU3iM6R.js +0 -174
- package/docs/.vitepress/dist/assets/guide_components.md.CMU3iM6R.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_contributing.md.Crrv3T_0.js +0 -1
- package/docs/.vitepress/dist/assets/guide_contributing.md.Crrv3T_0.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_directives.md.DFwqvqOv.js +0 -140
- package/docs/.vitepress/dist/assets/guide_directives.md.DFwqvqOv.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_getting-started.md.DtaJPe0i.js +0 -107
- package/docs/.vitepress/dist/assets/guide_getting-started.md.DtaJPe0i.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_index.md.DtJVpLI9.js +0 -2
- package/docs/.vitepress/dist/assets/guide_index.md.DtJVpLI9.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_lifecycle.md.CfY3jlU1.js +0 -304
- package/docs/.vitepress/dist/assets/guide_lifecycle.md.CfY3jlU1.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_quick-start.md.CwdNNA21.js +0 -33
- package/docs/.vitepress/dist/assets/guide_quick-start.md.CwdNNA21.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_reactivity.md.DgTH0MTn.js +0 -135
- package/docs/.vitepress/dist/assets/guide_reactivity.md.DgTH0MTn.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_routing.md.nMB0QOBR.js +0 -193
- package/docs/.vitepress/dist/assets/guide_routing.md.nMB0QOBR.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_sfc.md.BUkWma1z.js +0 -187
- package/docs/.vitepress/dist/assets/guide_sfc.md.BUkWma1z.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_templating.md.XI3uUlYI.js +0 -119
- package/docs/.vitepress/dist/assets/guide_templating.md.XI3uUlYI.lean.js +0 -1
- package/docs/.vitepress/dist/assets/index.md.M4_o26kF.js +0 -23
- package/docs/.vitepress/dist/assets/index.md.M4_o26kF.lean.js +0 -1
- package/docs/.vitepress/dist/assets/inter-italic-cyrillic-ext.r48I6akx.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-cyrillic.By2_1cv3.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-greek-ext.1u6EdAuj.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-greek.DJ8dCoTZ.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-latin-ext.CN1xVJS-.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-latin.C2AdPX0b.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-italic-vietnamese.BSbpV94h.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-cyrillic-ext.BBPuwvHQ.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-cyrillic.C5lxZ8CY.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-greek-ext.CqjqNYQ-.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-greek.BBVDIX6e.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-latin-ext.4ZJIpNVo.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-latin.Di8DUHzh.woff2 +0 -0
- package/docs/.vitepress/dist/assets/inter-roman-vietnamese.BjW4sHH5.woff2 +0 -0
- package/docs/.vitepress/dist/assets/style.eycE2Jhw.css +0 -1
- package/docs/.vitepress/dist/examples/form.html +0 -58
- package/docs/.vitepress/dist/examples/index.html +0 -52
- package/docs/.vitepress/dist/examples/routing.html +0 -362
- package/docs/.vitepress/dist/examples/sfc-showcase.html +0 -37
- package/docs/.vitepress/dist/examples/todo-app.html +0 -321
- package/docs/.vitepress/dist/guide/cdn-usage.html +0 -206
- package/docs/.vitepress/dist/guide/components.html +0 -198
- package/docs/.vitepress/dist/guide/contributing.html +0 -25
- package/docs/.vitepress/dist/guide/directives.html +0 -164
- package/docs/.vitepress/dist/guide/getting-started.html +0 -131
- package/docs/.vitepress/dist/guide/index.html +0 -26
- package/docs/.vitepress/dist/guide/lifecycle.html +0 -328
- package/docs/.vitepress/dist/guide/quick-start.html +0 -57
- package/docs/.vitepress/dist/guide/reactivity.html +0 -159
- package/docs/.vitepress/dist/guide/routing.html +0 -217
- package/docs/.vitepress/dist/guide/sfc.html +0 -211
- package/docs/.vitepress/dist/guide/templating.html +0 -143
- package/docs/.vitepress/dist/hashmap.json +0 -1
- package/docs/.vitepress/dist/index.html +0 -47
- package/docs/.vitepress/dist/logo.svg +0 -38
- package/docs/.vitepress/dist/vp-icons.css +0 -1
- package/examples/vite-app/src/main.js +0 -11
- package/examples.js +0 -99
package/docs/guide/components.md
CHANGED
|
@@ -36,10 +36,14 @@ A component is a reusable, self-contained piece of UI with its own template, sty
|
|
|
36
36
|
Define components directly in your HTML with `<template b-id>`:
|
|
37
37
|
|
|
38
38
|
```html
|
|
39
|
-
<template b-id="hello-world">
|
|
39
|
+
<template b-id="hello-world" b-data="{ name: 'Default User' }">
|
|
40
40
|
<h1>Hello {{ name }}!</h1>
|
|
41
41
|
</template>
|
|
42
42
|
|
|
43
|
+
<!-- Uses the default "Default User" -->
|
|
44
|
+
<hello-world></hello-world>
|
|
45
|
+
|
|
46
|
+
<!-- Overrides the default with "Alice" -->
|
|
43
47
|
<hello-world b-data="{ name: 'Alice' }"></hello-world>
|
|
44
48
|
```
|
|
45
49
|
|
|
@@ -113,24 +117,38 @@ Access state in templates using `{{ }}`:
|
|
|
113
117
|
}"></user-card>
|
|
114
118
|
```
|
|
115
119
|
|
|
116
|
-
### Merging
|
|
120
|
+
### Data Merging (The Three Tiers)
|
|
117
121
|
|
|
118
|
-
|
|
122
|
+
Lego uses a sophisticated three-tier merging strategy to initialize component state. This allows you to define defaults at the library level, customize them for a component type, and then override them for specific instances.
|
|
119
123
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
The priority is as follows (**last one wins**):
|
|
125
|
+
|
|
126
|
+
1. **Tier 1: Script Logic** - Data defined in `Lego.define()` or exported from a `.lego` SFC.
|
|
127
|
+
2. **Tier 2: Template Defaults** - Data defined on the `<template b-data="...">` attribute.
|
|
128
|
+
3. **Tier 3: Instance Overrides** - Data defined on the actual component tag `<my-comp b-data="...">`.
|
|
129
|
+
|
|
130
|
+
### Example of Merging
|
|
127
131
|
|
|
128
132
|
```html
|
|
129
|
-
<!--
|
|
133
|
+
<!-- 1. Script Logic (Defined in JS) -->
|
|
134
|
+
<script>
|
|
135
|
+
Lego.define('user-card', `...`, { role: 'guest', theme: 'light' });
|
|
136
|
+
</script>
|
|
137
|
+
|
|
138
|
+
<!-- 2. Template Defaults (Defined in HTML) -->
|
|
139
|
+
<template b-id="user-card" b-data="{ role: 'member', name: 'Anonymous' }">
|
|
140
|
+
...
|
|
141
|
+
</template>
|
|
142
|
+
|
|
143
|
+
<!-- 3. Instance Overrides -->
|
|
130
144
|
<user-card b-data="{ name: 'Alice' }"></user-card>
|
|
131
|
-
<!-- email and role use defaults -->
|
|
132
145
|
```
|
|
133
146
|
|
|
147
|
+
In the example above, the final state for the component will be:
|
|
148
|
+
- `role`: `'member'` (Template override beats Script)
|
|
149
|
+
- `theme`: `'light'` (Only defined in Script)
|
|
150
|
+
- `name`: `'Alice'` (Instance override beats Template)
|
|
151
|
+
|
|
134
152
|
## Component Communication
|
|
135
153
|
|
|
136
154
|
### Parent → Child (Props)
|
|
@@ -326,12 +344,12 @@ Clear timers, remove listeners:
|
|
|
326
344
|
### Loading States
|
|
327
345
|
|
|
328
346
|
```html
|
|
329
|
-
<div b-
|
|
330
|
-
<div b-
|
|
347
|
+
<div b-show="loading">Loading...</div>
|
|
348
|
+
<div b-show="!loading && data">
|
|
331
349
|
<h2>{{ data.title }}</h2>
|
|
332
350
|
<p>{{ data.content }}</p>
|
|
333
351
|
</div>
|
|
334
|
-
<div b-
|
|
352
|
+
<div b-show="!loading && error">
|
|
335
353
|
Error: {{ error }}
|
|
336
354
|
</div>
|
|
337
355
|
```
|
package/docs/guide/directives.md
CHANGED
|
@@ -2,34 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
Directives are special attributes that add reactive behavior to elements.
|
|
4
4
|
|
|
5
|
-
## b-
|
|
5
|
+
## b-show
|
|
6
6
|
|
|
7
7
|
Conditional rendering using `display: none`.
|
|
8
8
|
|
|
9
9
|
### Basic Usage
|
|
10
10
|
|
|
11
11
|
```html
|
|
12
|
-
<p b-
|
|
13
|
-
<p b-
|
|
12
|
+
<p b-show="isLoggedIn">Welcome back!</p>
|
|
13
|
+
<p b-show="!isLoggedIn">Please log in</p>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
### With Expressions
|
|
17
17
|
|
|
18
18
|
```html
|
|
19
|
-
<div b-
|
|
20
|
-
<div b-
|
|
21
|
-
<div b-
|
|
19
|
+
<div b-show="count > 0">Count is {{ count }}</div>
|
|
20
|
+
<div b-show="items.length === 0">No items</div>
|
|
21
|
+
<div b-show="user && user.role === 'admin'">Admin panel</div>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
### Multiple Conditions
|
|
25
25
|
|
|
26
26
|
```html
|
|
27
|
-
<p b-
|
|
28
|
-
<p b-
|
|
27
|
+
<p b-show="isLoggedIn && isPremium">Premium content</p>
|
|
28
|
+
<p b-show="age >= 18 || hasParentConsent">Access granted</p>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
::: tip How it Works
|
|
32
|
-
`b-
|
|
32
|
+
`b-show` sets `display: none` when the condition is false. The element stays in the DOM but is hidden.
|
|
33
33
|
:::
|
|
34
34
|
|
|
35
35
|
## b-for
|
|
@@ -83,8 +83,8 @@ Use `$index` (implicit variable):
|
|
|
83
83
|
|
|
84
84
|
```html
|
|
85
85
|
<li b-for="user in users">
|
|
86
|
-
<span b-
|
|
87
|
-
<span b-
|
|
86
|
+
<span b-show="user.active">✅ {{ user.name }}</span>
|
|
87
|
+
<span b-show="!user.active">❌ {{ user.name }}</span>
|
|
88
88
|
</li>
|
|
89
89
|
```
|
|
90
90
|
|
|
@@ -103,7 +103,7 @@ Two-way data binding for form inputs.
|
|
|
103
103
|
|
|
104
104
|
```html
|
|
105
105
|
<input type="checkbox" b-sync="agreed">
|
|
106
|
-
<p b-
|
|
106
|
+
<p b-show="agreed">You agreed to the terms</p>
|
|
107
107
|
```
|
|
108
108
|
|
|
109
109
|
### Radio Buttons
|
|
@@ -268,10 +268,10 @@ Lego.define('user-card', `...`, {
|
|
|
268
268
|
|
|
269
269
|
## Combining Directives
|
|
270
270
|
|
|
271
|
-
### b-
|
|
271
|
+
### b-show + b-for
|
|
272
272
|
|
|
273
273
|
```html
|
|
274
|
-
<li b-for="item in items" b-
|
|
274
|
+
<li b-for="item in items" b-show="item.visible">
|
|
275
275
|
{{ item.name }}
|
|
276
276
|
</li>
|
|
277
277
|
```
|
|
@@ -296,11 +296,11 @@ Lego.define('user-card', `...`, {
|
|
|
296
296
|
|
|
297
297
|
## Best Practices
|
|
298
298
|
|
|
299
|
-
### 1. Use b-
|
|
299
|
+
### 1. Use b-show for Show/Hide
|
|
300
300
|
|
|
301
301
|
```html
|
|
302
302
|
<!-- ✅ Clean -->
|
|
303
|
-
<div b-
|
|
303
|
+
<div b-show="showPanel">Panel content</div>
|
|
304
304
|
|
|
305
305
|
<!-- ❌ Verbose -->
|
|
306
306
|
<div style="display: {{ showPanel ? 'block' : 'none' }}">Panel content</div>
|
|
@@ -344,9 +344,9 @@ Move complex logic to methods.
|
|
|
344
344
|
|
|
345
345
|
## Performance Tips
|
|
346
346
|
|
|
347
|
-
### b-
|
|
347
|
+
### b-show vs CSS
|
|
348
348
|
|
|
349
|
-
`b-
|
|
349
|
+
`b-show` is fine for most cases, but for frequently toggled elements, use CSS:
|
|
350
350
|
|
|
351
351
|
```html
|
|
352
352
|
<!-- For frequent toggling -->
|
|
@@ -386,7 +386,7 @@ Paginate large lists:
|
|
|
386
386
|
|
|
387
387
|
```html
|
|
388
388
|
<button @click="visible = !visible">Toggle</button>
|
|
389
|
-
<div b-
|
|
389
|
+
<div b-show="visible">Content</div>
|
|
390
390
|
```
|
|
391
391
|
|
|
392
392
|
### Counter
|
|
@@ -418,9 +418,9 @@ Paginate large lists:
|
|
|
418
418
|
<button @click="activeTab = 'settings'">Settings</button>
|
|
419
419
|
</nav>
|
|
420
420
|
|
|
421
|
-
<div b-
|
|
422
|
-
<div b-
|
|
423
|
-
<div b-
|
|
421
|
+
<div b-show="activeTab === 'home'">Home content</div>
|
|
422
|
+
<div b-show="activeTab === 'profile'">Profile content</div>
|
|
423
|
+
<div b-show="activeTab === 'settings'">Settings content</div>
|
|
424
424
|
```
|
|
425
425
|
|
|
426
426
|
## Next Steps
|
|
@@ -18,8 +18,10 @@ The fastest way to try Lego is via CDN:
|
|
|
18
18
|
<my-component></my-component>
|
|
19
19
|
|
|
20
20
|
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
21
|
-
<template b-id="my-component">
|
|
21
|
+
<template b-id="my-component" b-data="{ count: 0 }">
|
|
22
22
|
<h1>Hello Lego!</h1>
|
|
23
|
+
<button @click="count++">Click me</button>
|
|
24
|
+
<p>Count: {{ count }}</p>
|
|
23
25
|
</template>
|
|
24
26
|
</body>
|
|
25
27
|
</html>
|
|
@@ -42,7 +44,11 @@ import { Lego } from 'lego-dom';
|
|
|
42
44
|
|
|
43
45
|
Lego.define('my-component', `
|
|
44
46
|
<h1>Hello Lego!</h1>
|
|
45
|
-
|
|
47
|
+
<button @click="count++">Click me</button>
|
|
48
|
+
<p>Count: {{ count }}</p>
|
|
49
|
+
`, {
|
|
50
|
+
count: 0,
|
|
51
|
+
});
|
|
46
52
|
```
|
|
47
53
|
|
|
48
54
|
### Option 3: With Vite (Recommended for Larger Projects)
|
|
@@ -66,6 +72,21 @@ export default defineConfig({
|
|
|
66
72
|
});
|
|
67
73
|
```
|
|
68
74
|
|
|
75
|
+
### The Runtime Engine
|
|
76
|
+
|
|
77
|
+
Crucially, you must initialize the Lego background engine in your entry file (`src/main.js`):
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
import { Lego } from 'lego-dom';
|
|
81
|
+
import registerComponents from 'virtual:lego-components';
|
|
82
|
+
|
|
83
|
+
// 1. Register SFCs
|
|
84
|
+
registerComponents();
|
|
85
|
+
|
|
86
|
+
// 2. Start the Engine (Async)
|
|
87
|
+
await Lego.init();
|
|
88
|
+
```
|
|
89
|
+
|
|
69
90
|
## Your First Component
|
|
70
91
|
|
|
71
92
|
Let's create a simple counter component.
|
|
@@ -73,7 +94,7 @@ Let's create a simple counter component.
|
|
|
73
94
|
### Using HTML Templates
|
|
74
95
|
|
|
75
96
|
```html
|
|
76
|
-
<template b-id="click-counter">
|
|
97
|
+
<template b-id="click-counter" b-data="{ message: 'Welcome!', count: 0 }">
|
|
77
98
|
<style>
|
|
78
99
|
self {
|
|
79
100
|
display: block;
|
|
@@ -96,12 +117,15 @@ Let's create a simple counter component.
|
|
|
96
117
|
}
|
|
97
118
|
</style>
|
|
98
119
|
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
120
|
+
<template b-id="click-counter" b-data="{ message: 'Welcome!', count: 0 }">
|
|
121
|
+
... markup ...
|
|
122
|
+
</template>
|
|
123
|
+
|
|
124
|
+
<!-- Uses defaults: message="Welcome!", count=0 -->
|
|
125
|
+
<click-counter></click-counter>
|
|
103
126
|
|
|
104
|
-
|
|
127
|
+
<!-- Overrides message, keeps count=0 -->
|
|
128
|
+
<click-counter b-data="{ message: 'Bienvenido!' }"></click-counter>
|
|
105
129
|
|
|
106
130
|
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
107
131
|
```
|
|
@@ -208,12 +232,12 @@ Use `@eventname` to handle events:
|
|
|
208
232
|
|
|
209
233
|
Special attributes for common patterns:
|
|
210
234
|
|
|
211
|
-
- `b-
|
|
235
|
+
- `b-show` - Conditional rendering
|
|
212
236
|
- `b-for` - List rendering
|
|
213
237
|
- `b-sync` - Two-way binding
|
|
214
238
|
|
|
215
239
|
```html
|
|
216
|
-
<p b-
|
|
240
|
+
<p b-show="isLoggedIn">Welcome back!</p>
|
|
217
241
|
<li b-for="item in items">{{ item.name }}</li>
|
|
218
242
|
<input b-sync="username" />
|
|
219
243
|
```
|
|
@@ -224,6 +248,7 @@ Special attributes for common patterns:
|
|
|
224
248
|
- ✅ How to create your first component
|
|
225
249
|
- ✅ The basics of templates, state, and events
|
|
226
250
|
- ✅ Available directives
|
|
251
|
+
- ✅ The importance of the `Lego.init()` engine
|
|
227
252
|
|
|
228
253
|
## Next Steps
|
|
229
254
|
|
package/docs/guide/index.md
CHANGED
|
@@ -64,8 +64,8 @@ No proprietary APIs. Everything is built on web standards.
|
|
|
64
64
|
The core library (`main.js`) is **under 500 lines** of well-commented JavaScript.
|
|
65
65
|
|
|
66
66
|
- **No dependencies** - Zero `node_modules` bloat
|
|
67
|
-
- **~
|
|
68
|
-
- **~
|
|
67
|
+
- **~22KB** - Unminified, human-readable code
|
|
68
|
+
- **~7KB** - Minified and gzipped
|
|
69
69
|
|
|
70
70
|
Compare that to:
|
|
71
71
|
- Vue 3: ~33KB (minified + gzipped)
|
|
@@ -77,7 +77,7 @@ Compare that to:
|
|
|
77
77
|
| Aspect | Lego | Traditional Frameworks |
|
|
78
78
|
|--------|--------|----------------------|
|
|
79
79
|
| **Reactivity** | Direct object mutation | setState / dispatch / ref() |
|
|
80
|
-
| **Templates** | HTML with
|
|
80
|
+
| **Templates** | HTML with <code v-pre>{{ }}</code> | JSX / template syntax |
|
|
81
81
|
| **Styles** | Shadow DOM (native) | CSS-in-JS / scoped CSS |
|
|
82
82
|
| **Build** | Optional | Required |
|
|
83
83
|
| **Learning Curve** | Hours | Days/Weeks |
|
|
@@ -27,7 +27,7 @@ The fastest way to get started with Lego is using the CDN. No build tools requir
|
|
|
27
27
|
<!-- 4. Load Lego -->
|
|
28
28
|
<script src="https://unpkg.com/lego-dom/main.js"></script>
|
|
29
29
|
|
|
30
|
-
<!-- 5. Define logic
|
|
30
|
+
<!-- 5. Define logic & Init -->
|
|
31
31
|
<script>
|
|
32
32
|
document.querySelector('hello-world').state = {
|
|
33
33
|
name: 'World',
|
|
@@ -35,6 +35,9 @@ The fastest way to get started with Lego is using the CDN. No build tools requir
|
|
|
35
35
|
this.name = this.name === 'World' ? 'Lego' : 'World';
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
|
|
39
|
+
// Start the engine
|
|
40
|
+
Lego.init();
|
|
38
41
|
</script>
|
|
39
42
|
</body>
|
|
40
43
|
</html>
|
package/docs/guide/reactivity.md
CHANGED
|
@@ -145,11 +145,32 @@ This prevents unnecessary DOM updates and improves performance.
|
|
|
145
145
|
|
|
146
146
|
updated() {
|
|
147
147
|
console.log('DOM updated with:', this.count);
|
|
148
|
-
// DOM is updated now!
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
150
|
```
|
|
152
151
|
|
|
152
|
+
## Global Reactivity
|
|
153
|
+
|
|
154
|
+
Lego also supports **Global State** available to all components and the main document.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
// src/main.js
|
|
158
|
+
Lego.globals.isLoggedIn = true;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
For global state to automatically update mustaches in your `index.html`, you must initialize the engine:
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
// Enables global reactivity and the MutationObserver
|
|
165
|
+
Lego.init();
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Inside any component, you can access global state via `global`:
|
|
169
|
+
|
|
170
|
+
```html
|
|
171
|
+
<p b-show="global.isLoggedIn">Welcome!</p>
|
|
172
|
+
```
|
|
173
|
+
|
|
153
174
|
## Deep Reactivity
|
|
154
175
|
|
|
155
176
|
Nested objects are automatically reactive:
|