lego-dom 1.0.0 → 1.3.4
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/.legodom +87 -0
- package/CHANGELOG.md +87 -3
- package/cdn.html +10 -5
- package/docs/.vitepress/config.js +23 -7
- package/docs/api/config.md +95 -0
- package/docs/api/define.md +29 -2
- package/docs/api/directives.md +10 -2
- package/docs/api/index.md +1 -0
- package/docs/contributing/01-welcome.md +2 -0
- package/docs/contributing/02-registry.md +37 -3
- package/docs/contributing/06-init.md +13 -2
- package/docs/contributing/07-observer.md +3 -0
- package/docs/contributing/08-snap.md +15 -1
- package/docs/contributing/10-studs.md +3 -1
- package/docs/contributing/11-scanner.md +13 -0
- package/docs/contributing/12-render.md +32 -10
- package/docs/contributing/13-directives.md +19 -1
- package/docs/contributing/14-events.md +1 -1
- package/docs/contributing/15-router.md +49 -1
- package/docs/contributing/16-state.md +9 -10
- package/docs/contributing/17-legodom.md +1 -8
- package/docs/contributing/index.md +23 -4
- package/docs/examples/form.md +1 -1
- package/docs/examples/index.md +3 -3
- package/docs/examples/routing.md +10 -10
- package/docs/examples/sfc-showcase.md +1 -1
- package/docs/examples/todo-app.md +7 -7
- package/docs/guide/cdn-usage.md +44 -18
- package/docs/guide/components.md +18 -12
- package/docs/guide/directives.md +131 -22
- package/docs/guide/directory-structure.md +248 -0
- package/docs/guide/faq.md +210 -0
- package/docs/guide/getting-started.md +14 -10
- package/docs/guide/index.md +1 -1
- package/docs/guide/lifecycle.md +32 -0
- package/docs/guide/quick-start.md +4 -4
- package/docs/guide/reactivity.md +2 -2
- package/docs/guide/routing.md +69 -8
- package/docs/guide/server-side.md +134 -0
- package/docs/guide/sfc.md +96 -13
- package/docs/guide/templating.md +62 -57
- package/docs/index.md +9 -9
- package/docs/router/basic-routing.md +8 -8
- package/docs/router/cold-entry.md +2 -2
- package/docs/router/history.md +7 -7
- package/docs/router/index.md +1 -1
- package/docs/router/resolver.md +5 -5
- package/docs/router/surgical-swaps.md +5 -5
- package/docs/tutorial/01-project-setup.md +152 -0
- package/docs/tutorial/02-your-first-component.md +226 -0
- package/docs/tutorial/03-adding-routes.md +279 -0
- package/docs/tutorial/04-multi-page-app.md +329 -0
- package/docs/tutorial/05-state-and-globals.md +285 -0
- package/docs/tutorial/index.md +40 -0
- package/examples/vite-app/index.html +1 -0
- package/examples/vite-app/src/app.js +2 -2
- package/examples/vite-app/src/components/side-menu.lego +46 -0
- package/examples/vite-app/vite.config.js +2 -1
- package/main.js +261 -72
- package/main.min.js +7 -0
- package/monitoring-plugin.js +111 -0
- package/package.json +4 -2
- package/parse-lego.js +49 -22
- package/tests/error.test.js +74 -0
- package/tests/main.test.js +2 -2
- package/tests/memory.test.js +68 -0
- package/tests/monitoring.test.js +74 -0
- package/tests/naming.test.js +74 -0
- package/tests/parse-lego.test.js +2 -2
- package/tests/security.test.js +67 -0
- package/tests/server.test.js +114 -0
- package/tests/syntax.test.js +67 -0
- package/vite-plugin.js +3 -2
- package/docs/guide/contributing.md +0 -32
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import { JSDOM } from 'jsdom';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>', {
|
|
7
|
+
runScripts: "dangerously",
|
|
8
|
+
resources: "usable"
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
global.window = dom.window;
|
|
12
|
+
global.document = dom.window.document;
|
|
13
|
+
Object.defineProperty(global, 'navigator', { value: dom.window.navigator });
|
|
14
|
+
global.HTMLElement = dom.window.HTMLElement;
|
|
15
|
+
global.customElements = dom.window.customElements;
|
|
16
|
+
global.MutationObserver = dom.window.MutationObserver;
|
|
17
|
+
global.Node = dom.window.Node;
|
|
18
|
+
global.NodeFilter = dom.window.NodeFilter;
|
|
19
|
+
global.Element = dom.window.Element;
|
|
20
|
+
global.Event = dom.window.Event;
|
|
21
|
+
global.requestAnimationFrame = (cb) => setTimeout(cb, 0);
|
|
22
|
+
|
|
23
|
+
const libCode = fs.readFileSync(path.resolve(__dirname, '../main.js'), 'utf8');
|
|
24
|
+
eval(libCode);
|
|
25
|
+
|
|
26
|
+
describe('LegoDOM Configurable Syntax', () => {
|
|
27
|
+
beforeEach(async () => {
|
|
28
|
+
document.body.innerHTML = '';
|
|
29
|
+
window.Lego.config.syntax = 'brackets'; // Explicitly set default (though it's default in main.js now)
|
|
30
|
+
await window.Lego.init(document.body);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
window.Lego.config.syntax = 'brackets'; // Reset
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should render [[ ]] by default', async () => {
|
|
38
|
+
window.Lego.define('default-syntax', '<div>[[ msg ]]</div>');
|
|
39
|
+
const el = document.createElement('default-syntax');
|
|
40
|
+
el.setAttribute('b-data', "{ msg: 'Hello' }");
|
|
41
|
+
document.body.appendChild(el);
|
|
42
|
+
await new Promise(r => setTimeout(r, 100));
|
|
43
|
+
expect(el.shadowRoot.textContent).toBe('Hello');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should render {{ }} when syntax is mustache', async () => {
|
|
47
|
+
window.Lego.config.syntax = 'mustache';
|
|
48
|
+
|
|
49
|
+
window.Lego.define('mustache-syntax', '<div>{{ msg }}</div>');
|
|
50
|
+
const el = document.createElement('mustache-syntax');
|
|
51
|
+
el.setAttribute('b-data', "{ msg: 'Mustache World' }");
|
|
52
|
+
document.body.appendChild(el);
|
|
53
|
+
await new Promise(r => setTimeout(r, 100));
|
|
54
|
+
expect(el.shadowRoot.textContent).toBe('Mustache World');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should ignore {{ }} when syntax is brackets', async () => {
|
|
58
|
+
// Default is brackets
|
|
59
|
+
// {{ msg }} should be treated as literal text
|
|
60
|
+
window.Lego.define('mixed-syntax', '<div>{{ msg }} - [[ msg ]]</div>');
|
|
61
|
+
const el = document.createElement('mixed-syntax');
|
|
62
|
+
el.setAttribute('b-data', "{ msg: 'Active' }");
|
|
63
|
+
document.body.appendChild(el);
|
|
64
|
+
await new Promise(r => setTimeout(r, 100));
|
|
65
|
+
expect(el.shadowRoot.textContent).toBe('{{ msg }} - Active');
|
|
66
|
+
});
|
|
67
|
+
});
|
package/vite-plugin.js
CHANGED
|
@@ -20,7 +20,8 @@ const RESOLVED_VIRTUAL_MODULE_ID = '\0' + VIRTUAL_MODULE_ID;
|
|
|
20
20
|
export default function legoPlugin(options = {}) {
|
|
21
21
|
const {
|
|
22
22
|
componentsDir = './src/components',
|
|
23
|
-
include = ['**/*.lego']
|
|
23
|
+
include = ['**/*.lego'],
|
|
24
|
+
importPath = 'lego-dom'
|
|
24
25
|
} = options;
|
|
25
26
|
|
|
26
27
|
let config;
|
|
@@ -132,7 +133,7 @@ export default function legoPlugin(options = {}) {
|
|
|
132
133
|
const defineCall = generateDefineCall(parsed);
|
|
133
134
|
|
|
134
135
|
return `
|
|
135
|
-
import { Lego } from '
|
|
136
|
+
import { Lego } from '${importPath}';
|
|
136
137
|
|
|
137
138
|
${defineCall}
|
|
138
139
|
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
Thank you for your interest in contributing to Lego!
|
|
4
|
-
|
|
5
|
-
## Development Setup
|
|
6
|
-
|
|
7
|
-
1. Clone the repository:
|
|
8
|
-
```bash
|
|
9
|
-
git clone https://github.com/rayattack/Lego.git
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
2. Install dependencies:
|
|
13
|
-
```bash
|
|
14
|
-
yarn install
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
3. Run the dev server for docs:
|
|
18
|
-
```bash
|
|
19
|
-
yarn docs:dev
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Pull Requests
|
|
23
|
-
|
|
24
|
-
1. Fork the repo and create your branch from `main`.
|
|
25
|
-
2. If you've added code that should be tested, add tests.
|
|
26
|
-
3. If you've changed APIs, update the documentation.
|
|
27
|
-
4. Ensure the test suite passes.
|
|
28
|
-
5. Make sure your code lints.
|
|
29
|
-
|
|
30
|
-
## License
|
|
31
|
-
|
|
32
|
-
By contributing, you agree that your contributions will be licensed under its MIT License.
|