lego-dom 0.0.8 → 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 +49 -432
- package/cdn.html +124 -0
- package/docs/.vitepress/config.js +43 -5
- package/docs/api/directives.md +3 -3
- package/docs/api/globals.md +1 -1
- package/docs/api/index.md +3 -3
- package/docs/api/vite-plugin.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 +2 -2
- package/docs/examples/index.md +4 -4
- package/docs/examples/routing.md +8 -8
- package/docs/examples/sfc-showcase.md +4 -4
- package/docs/examples/todo-app.md +3 -3
- package/docs/guide/cdn-usage.md +16 -8
- package/docs/guide/components.md +34 -16
- package/docs/guide/contributing.md +2 -2
- package/docs/guide/directives.md +23 -23
- package/docs/guide/getting-started.md +41 -16
- package/docs/guide/index.md +12 -12
- package/docs/guide/lifecycle.md +1 -1
- package/docs/guide/quick-start.md +8 -5
- package/docs/guide/reactivity.md +30 -9
- package/docs/guide/routing.md +189 -289
- package/docs/guide/sfc.md +40 -40
- package/docs/guide/templating.md +4 -4
- package/docs/index.md +48 -14
- package/docs/public/logo.svg +17 -38
- 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/README.md +2 -2
- package/examples/vite-app/index.html +9 -13
- 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 +26 -26
- package/examples/vite-app/src/components/sample-component.lego +58 -58
- package/examples/vite-app/src/components/shells/customers-shell.lego +21 -0
- package/examples/vite-app/src/components/todo-list.lego +239 -0
- package/examples/vite-app/src/components/widgets/user-card.lego +27 -0
- package/examples/vite-app/vite.config.js +7 -2
- package/lego.js +2 -0
- package/main.js +280 -83
- package/package.json +8 -3
- package/parse-lego.js +17 -8
- package/parse-lego.test.js +1 -1
- package/{main.test.js → tests/main.test.js} +34 -17
- package/tests/parse-lego.test.js +65 -0
- package/vite-plugin.js +62 -24
- 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.DOjt7AV0.js +0 -3
- package/docs/.vitepress/dist/assets/api_globals.md.DOjt7AV0.lean.js +0 -1
- package/docs/.vitepress/dist/assets/api_index.md.OS6h01ct.js +0 -1
- package/docs/.vitepress/dist/assets/api_index.md.OS6h01ct.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.DNn9VhL5.js +0 -13
- package/docs/.vitepress/dist/assets/api_vite-plugin.md.DNn9VhL5.lean.js +0 -1
- package/docs/.vitepress/dist/assets/app.BG5s3B0P.js +0 -1
- package/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.DQmuWC2Z.js +0 -1
- package/docs/.vitepress/dist/assets/chunks/VPLocalSearchBox.BO-PSxt1.js +0 -9
- package/docs/.vitepress/dist/assets/chunks/framework.B7OFBR9X.js +0 -19
- package/docs/.vitepress/dist/assets/chunks/theme.DA-iSa9B.js +0 -2
- package/docs/.vitepress/dist/assets/examples_form.md.B3stGKbu.js +0 -34
- package/docs/.vitepress/dist/assets/examples_form.md.B3stGKbu.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_index.md.BDEG_D4J.js +0 -30
- package/docs/.vitepress/dist/assets/examples_index.md.BDEG_D4J.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_routing.md.bqZ9DjDK.js +0 -338
- package/docs/.vitepress/dist/assets/examples_routing.md.bqZ9DjDK.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_sfc-showcase.md.DLXaUiop.js +0 -13
- package/docs/.vitepress/dist/assets/examples_sfc-showcase.md.DLXaUiop.lean.js +0 -1
- package/docs/.vitepress/dist/assets/examples_todo-app.md.D5RhZoo5.js +0 -297
- package/docs/.vitepress/dist/assets/examples_todo-app.md.D5RhZoo5.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_cdn-usage.md.CAjf03Lr.js +0 -182
- package/docs/.vitepress/dist/assets/guide_cdn-usage.md.CAjf03Lr.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_components.md.BIFWF1Hc.js +0 -174
- package/docs/.vitepress/dist/assets/guide_components.md.BIFWF1Hc.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_contributing.md.BgbUN-Mr.js +0 -1
- package/docs/.vitepress/dist/assets/guide_contributing.md.BgbUN-Mr.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_directives.md.Bi3ynu1d.js +0 -140
- package/docs/.vitepress/dist/assets/guide_directives.md.Bi3ynu1d.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_getting-started.md.2Nr1lp2z.js +0 -107
- package/docs/.vitepress/dist/assets/guide_getting-started.md.2Nr1lp2z.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_index.md.GvZq_Yf2.js +0 -2
- package/docs/.vitepress/dist/assets/guide_index.md.GvZq_Yf2.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_lifecycle.md.B28j1OzS.js +0 -304
- package/docs/.vitepress/dist/assets/guide_lifecycle.md.B28j1OzS.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_quick-start.md.CNk3VGTF.js +0 -33
- package/docs/.vitepress/dist/assets/guide_quick-start.md.CNk3VGTF.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_reactivity.md.CVsaMaPv.js +0 -135
- package/docs/.vitepress/dist/assets/guide_reactivity.md.CVsaMaPv.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_routing.md.DSpDP25o.js +0 -193
- package/docs/.vitepress/dist/assets/guide_routing.md.DSpDP25o.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_sfc.md.CVUP66tS.js +0 -187
- package/docs/.vitepress/dist/assets/guide_sfc.md.CVUP66tS.lean.js +0 -1
- package/docs/.vitepress/dist/assets/guide_templating.md.BgCGe4aa.js +0 -119
- package/docs/.vitepress/dist/assets/guide_templating.md.BgCGe4aa.lean.js +0 -1
- package/docs/.vitepress/dist/assets/index.md.xV1taCED.js +0 -23
- package/docs/.vitepress/dist/assets/index.md.xV1taCED.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 -368
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Components
|
|
2
2
|
|
|
3
|
-
Learn how to create and use components in
|
|
3
|
+
Learn how to create and use components in Lego.
|
|
4
4
|
|
|
5
5
|
## What is a Component?
|
|
6
6
|
|
|
@@ -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
|
```
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Contributing
|
|
2
2
|
|
|
3
|
-
Thank you for your interest in contributing to
|
|
3
|
+
Thank you for your interest in contributing to Lego!
|
|
4
4
|
|
|
5
5
|
## Development Setup
|
|
6
6
|
|
|
7
7
|
1. Clone the repository:
|
|
8
8
|
```bash
|
|
9
|
-
git clone https://github.com/rayattack/
|
|
9
|
+
git clone https://github.com/rayattack/Lego.git
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
2. Install dependencies:
|
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
|
|
@@ -243,7 +243,7 @@ Initialize component state.
|
|
|
243
243
|
```html
|
|
244
244
|
<todo-list b-data="{
|
|
245
245
|
todos: [
|
|
246
|
-
{ text: 'Learn
|
|
246
|
+
{ text: 'Learn Lego', done: true },
|
|
247
247
|
{ text: 'Build app', done: false }
|
|
248
248
|
],
|
|
249
249
|
filter: 'all'
|
|
@@ -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
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
# Getting Started
|
|
2
2
|
|
|
3
|
-
Get up and running with
|
|
3
|
+
Get up and running with Lego in under 5 minutes.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
### Option 1: CDN (No Build Tools)
|
|
8
8
|
|
|
9
|
-
The fastest way to try
|
|
9
|
+
The fastest way to try Lego is via CDN:
|
|
10
10
|
|
|
11
11
|
```html
|
|
12
12
|
<!DOCTYPE html>
|
|
13
13
|
<html>
|
|
14
14
|
<head>
|
|
15
|
-
<title>My
|
|
15
|
+
<title>My Lego App</title>
|
|
16
16
|
</head>
|
|
17
17
|
<body>
|
|
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">
|
|
22
|
-
<h1>Hello
|
|
21
|
+
<template b-id="my-component" b-data="{ count: 0 }">
|
|
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>
|
|
@@ -41,8 +43,12 @@ Then import it:
|
|
|
41
43
|
import { Lego } from 'lego-dom';
|
|
42
44
|
|
|
43
45
|
Lego.define('my-component', `
|
|
44
|
-
<h1>Hello
|
|
45
|
-
|
|
46
|
+
<h1>Hello Lego!</h1>
|
|
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,22 +232,23 @@ 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
|
```
|
|
220
244
|
|
|
221
245
|
## What You've Learned
|
|
222
246
|
|
|
223
|
-
- ✅ Three different ways to install
|
|
247
|
+
- ✅ Three different ways to install Lego
|
|
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
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# What is
|
|
1
|
+
# What is Lego?
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
LegoDOM is a tiny, zero-dependency JavaScript library for building reactive Web Components directly in the browser.
|
|
4
4
|
|
|
5
5
|
## The Philosophy
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
LegoDOM is built on a simple belief: **the DOM is not your enemy**.
|
|
8
8
|
|
|
9
|
-
Modern frameworks introduced virtual DOMs and compilation steps to solve problems that arose from trying to make the DOM do things it wasn't designed for.
|
|
9
|
+
Modern frameworks introduced virtual DOMs and compilation steps to solve problems that arose from trying to make the DOM do things it wasn't designed for. Lego takes a different approach—it embraces the DOM and Web Components as they were intended to be used.
|
|
10
10
|
|
|
11
11
|
## Key Principles
|
|
12
12
|
|
|
@@ -17,7 +17,7 @@ There are no new concepts to learn. If you know:
|
|
|
17
17
|
- JavaScript objects
|
|
18
18
|
- Basic DOM events
|
|
19
19
|
|
|
20
|
-
You already know
|
|
20
|
+
You already know Lego.
|
|
21
21
|
|
|
22
22
|
### 2. No Build Step Required
|
|
23
23
|
|
|
@@ -34,7 +34,7 @@ component._studs.count++;
|
|
|
34
34
|
|
|
35
35
|
### 4. Web Standards First
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Lego uses:
|
|
38
38
|
- **Web Components** - Standard custom elements
|
|
39
39
|
- **Shadow DOM** - Native encapsulation
|
|
40
40
|
- **ES6 Proxies** - For reactivity
|
|
@@ -42,9 +42,9 @@ LegoJS uses:
|
|
|
42
42
|
|
|
43
43
|
No proprietary APIs. Everything is built on web standards.
|
|
44
44
|
|
|
45
|
-
## When to Use
|
|
45
|
+
## When to Use Lego
|
|
46
46
|
|
|
47
|
-
### ✅
|
|
47
|
+
### ✅ Lego is Great For:
|
|
48
48
|
|
|
49
49
|
- **Small to medium applications** where framework overhead isn't worth it
|
|
50
50
|
- **Embedded widgets** that need to work anywhere
|
|
@@ -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)
|
|
@@ -74,10 +74,10 @@ Compare that to:
|
|
|
74
74
|
|
|
75
75
|
## What Makes It Different?
|
|
76
76
|
|
|
77
|
-
| Aspect |
|
|
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 |
|
package/docs/guide/lifecycle.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Quick Start
|
|
2
2
|
|
|
3
|
-
The fastest way to get started with
|
|
3
|
+
The fastest way to get started with Lego is using the CDN. No build tools required!
|
|
4
4
|
|
|
5
5
|
## 1. Create an HTML file
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ The fastest way to get started with LegoJS is using the CDN. No build tools requ
|
|
|
9
9
|
<html lang="en">
|
|
10
10
|
<head>
|
|
11
11
|
<meta charset="UTF-8">
|
|
12
|
-
<title>
|
|
12
|
+
<title>Lego Quick Start</title>
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<!-- 2. Use your component -->
|
|
@@ -24,17 +24,20 @@ The fastest way to get started with LegoJS is using the CDN. No build tools requ
|
|
|
24
24
|
<button @click="toggle()">Toggle Name</button>
|
|
25
25
|
</template>
|
|
26
26
|
|
|
27
|
-
<!-- 4. Load
|
|
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',
|
|
34
34
|
toggle() {
|
|
35
|
-
this.name = this.name === 'World' ? '
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Reactivity
|
|
2
2
|
|
|
3
|
-
Understand how
|
|
3
|
+
Understand how Lego makes your UI automatically update when data changes.
|
|
4
4
|
|
|
5
5
|
## The Core Concept
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ No `setState()`, no `dispatch()`, no special syntax. Just mutate the data.
|
|
|
15
15
|
|
|
16
16
|
## How It Works
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Lego uses **ES6 Proxies** to track changes:
|
|
19
19
|
|
|
20
20
|
```js
|
|
21
21
|
const reactive = (obj, el) => {
|
|
@@ -62,7 +62,7 @@ this.items.sort(); // ✅ Reactive
|
|
|
62
62
|
this.user.profile.age = 30; // ✅ Reactive
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
Lego recursively wraps nested objects in proxies.
|
|
66
66
|
|
|
67
67
|
### ✅ Object Deletion
|
|
68
68
|
|
|
@@ -112,7 +112,7 @@ Initialize all properties upfront:
|
|
|
112
112
|
|
|
113
113
|
## Batching Updates
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
Lego batches updates using `requestAnimationFrame`:
|
|
116
116
|
|
|
117
117
|
```js
|
|
118
118
|
this.count = 1;
|
|
@@ -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:
|
|
@@ -296,7 +317,7 @@ console.log(component._studs.count); // Actual value
|
|
|
296
317
|
const count = ref(0);
|
|
297
318
|
count.value++;
|
|
298
319
|
|
|
299
|
-
//
|
|
320
|
+
// Lego
|
|
300
321
|
this.count++;
|
|
301
322
|
```
|
|
302
323
|
|
|
@@ -307,7 +328,7 @@ this.count++;
|
|
|
307
328
|
const [count, setCount] = useState(0);
|
|
308
329
|
setCount(count + 1);
|
|
309
330
|
|
|
310
|
-
//
|
|
331
|
+
// Lego
|
|
311
332
|
this.count++;
|
|
312
333
|
```
|
|
313
334
|
|
|
@@ -318,11 +339,11 @@ this.count++;
|
|
|
318
339
|
let count = 0;
|
|
319
340
|
count++;
|
|
320
341
|
|
|
321
|
-
//
|
|
342
|
+
// Lego
|
|
322
343
|
this.count++;
|
|
323
344
|
```
|
|
324
345
|
|
|
325
|
-
|
|
346
|
+
Lego is closest to Svelte's model but uses Proxies instead of compilation.
|
|
326
347
|
|
|
327
348
|
## Advanced Patterns
|
|
328
349
|
|