lightview 2.2.2 → 2.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/cDOMIntro.md +279 -0
- package/docs/about.html +15 -12
- package/docs/api/computed.html +1 -1
- package/docs/api/effects.html +1 -1
- package/docs/api/elements.html +56 -25
- package/docs/api/enhance.html +1 -1
- package/docs/api/hypermedia.html +1 -1
- package/docs/api/index.html +1 -1
- package/docs/api/nav.html +28 -3
- package/docs/api/signals.html +1 -1
- package/docs/api/state.html +283 -85
- package/docs/assets/js/examplify.js +2 -1
- package/docs/cdom-nav.html +3 -2
- package/docs/cdom.html +383 -114
- package/jprx/README.md +112 -71
- package/jprx/helpers/state.js +21 -0
- package/jprx/package.json +1 -1
- package/jprx/parser.js +136 -86
- package/jprx/specs/expressions.json +71 -0
- package/jprx/specs/helpers.json +150 -0
- package/lightview-all.js +618 -431
- package/lightview-cdom.js +311 -605
- package/lightview-router.js +6 -0
- package/lightview-x.js +226 -54
- package/lightview.js +351 -42
- package/package.json +2 -1
- package/src/lightview-cdom.js +211 -315
- package/src/lightview-router.js +10 -0
- package/src/lightview-x.js +121 -1
- package/src/lightview.js +88 -16
- package/src/reactivity/signal.js +73 -29
- package/src/reactivity/state.js +84 -21
- package/tests/cdom/fixtures/helpers.cdomc +24 -24
- package/tests/cdom/helpers.test.js +28 -28
- package/tests/cdom/parser.test.js +39 -114
- package/tests/cdom/reactivity.test.js +32 -29
- package/tests/jprx/spec.test.js +99 -0
- package/tests/cdom/loader.test.js +0 -125
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import Lightview from '../../src/lightview.js';
|
|
6
|
-
import LightviewX from '../../src/lightview-x.js';
|
|
7
|
-
import LightviewCDOM from '../../src/lightview-cdom.js';
|
|
8
|
-
|
|
9
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
|
|
11
|
-
describe('cdom Full Loader Tests', () => {
|
|
12
|
-
let handleSrc;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
globalThis.window = globalThis;
|
|
16
|
-
globalThis.__DEBUG__ = true;
|
|
17
|
-
globalThis.Lightview = Lightview;
|
|
18
|
-
globalThis.LightviewX = LightviewX;
|
|
19
|
-
globalThis.LightviewCDOM = LightviewCDOM;
|
|
20
|
-
|
|
21
|
-
if (typeof document !== 'undefined') {
|
|
22
|
-
document.body.innerHTML = '';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
Lightview.registry.clear();
|
|
26
|
-
LightviewX.state({
|
|
27
|
-
user: {
|
|
28
|
-
name: 'Alice',
|
|
29
|
-
age: 30,
|
|
30
|
-
role: 'Admin',
|
|
31
|
-
status: 'Available',
|
|
32
|
-
score: 100,
|
|
33
|
-
level: 5,
|
|
34
|
-
points: [10, 20, 30],
|
|
35
|
-
isVip: true,
|
|
36
|
-
account: { type: 'Premium' },
|
|
37
|
-
details: { city: 'NYC', zip: '10001' },
|
|
38
|
-
discount: 10,
|
|
39
|
-
activity: {
|
|
40
|
-
purchases: [5, 10, 15]
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}, 'app');
|
|
44
|
-
|
|
45
|
-
if (globalThis.LightviewX?.internals?.handleSrcAttribute) {
|
|
46
|
-
handleSrc = globalThis.LightviewX.internals.handleSrcAttribute;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
globalThis.fetch = vi.fn().mockImplementation((url) => {
|
|
50
|
-
const fileName = url.toString().split('/').pop();
|
|
51
|
-
const filePath = path.join(__dirname, 'fixtures', fileName);
|
|
52
|
-
if (!fs.existsSync(filePath)) return Promise.resolve({ ok: false, status: 404 });
|
|
53
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
54
|
-
return Promise.resolve({
|
|
55
|
-
ok: true,
|
|
56
|
-
text: () => Promise.resolve(content),
|
|
57
|
-
json: () => Promise.resolve(JSON.parse(content)),
|
|
58
|
-
url: url.toString()
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const cleanHTML = (html) => html.replace(/<!--lv:[se]-->/g, '').replace(/\s+/g, ' ').trim();
|
|
64
|
-
|
|
65
|
-
it('should load and parse user.vdom with cdom expressions', async () => {
|
|
66
|
-
const container = Lightview.tags.div({ src: '/user.vdom' });
|
|
67
|
-
await handleSrc(container, '/user.vdom', 'div', {
|
|
68
|
-
element: Lightview.element,
|
|
69
|
-
setupChildren: Lightview.internals.setupChildren
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const html = cleanHTML(container.domEl.innerHTML);
|
|
73
|
-
expect(html).toContain('Alice');
|
|
74
|
-
expect(html).toContain('Age: 30');
|
|
75
|
-
expect(html).toContain('Account: Premium');
|
|
76
|
-
expect(html).toContain('VIP Status: Yes');
|
|
77
|
-
expect(html).toContain('Location: NYC');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should load and parse user.odom with cdom expressions', async () => {
|
|
81
|
-
const container = Lightview.tags.div({ src: '/user.odom' });
|
|
82
|
-
await handleSrc(container, '/user.odom', 'div', {
|
|
83
|
-
element: Lightview.element,
|
|
84
|
-
setupChildren: Lightview.internals.setupChildren
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const html = cleanHTML(container.domEl.innerHTML);
|
|
88
|
-
expect(html).toContain('Alice');
|
|
89
|
-
expect(html).toContain('Score: 100');
|
|
90
|
-
expect(html).toContain('Level: 5');
|
|
91
|
-
// Activity: purchases [5, 10, 15] -> sum = 30
|
|
92
|
-
expect(html).toContain('Activity Total: 30');
|
|
93
|
-
// Relative path: ../discount (10) * sum(purchases...) (30) = 300
|
|
94
|
-
expect(html).toContain('With Discount: 300');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should load and parse user.cdom (JSON ODOM file)', async () => {
|
|
98
|
-
const container = Lightview.tags.div({ src: '/user.cdom' });
|
|
99
|
-
await handleSrc(container, '/user.cdom', 'div', {
|
|
100
|
-
element: Lightview.element,
|
|
101
|
-
setupChildren: Lightview.internals.setupChildren
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const html = cleanHTML(container.domEl.innerHTML);
|
|
105
|
-
expect(html).toContain('cdom-card');
|
|
106
|
-
expect(html).toContain('Welcome, Alice');
|
|
107
|
-
expect(html).toContain('(VIP)');
|
|
108
|
-
expect(html).toContain('Discount: 20%');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should load and parse user.cdomc (Unquoted Properties/Expressions)', async () => {
|
|
112
|
-
const container = Lightview.tags.div({ src: '/user.cdomc' });
|
|
113
|
-
await handleSrc(container, '/user.cdomc', 'div', {
|
|
114
|
-
element: Lightview.element,
|
|
115
|
-
setupChildren: Lightview.internals.setupChildren
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const html = cleanHTML(container.domEl.innerHTML);
|
|
119
|
-
if (__DEBUG__) console.log('ACTUAL HTML:', html);
|
|
120
|
-
expect(html).toContain('profile-compiled');
|
|
121
|
-
expect(html).toContain('Alice');
|
|
122
|
-
expect(html).toContain('Available');
|
|
123
|
-
expect(html).toContain('Tier: Platinum');
|
|
124
|
-
});
|
|
125
|
-
});
|