rask-ui 0.2.5 → 0.2.7
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/dist/vdom/AbstractVNode.d.ts +20 -1
- package/dist/vdom/AbstractVNode.d.ts.map +1 -1
- package/dist/vdom/AbstractVNode.js +151 -12
- package/dist/vdom/ComponentVNode.d.ts +2 -2
- package/dist/vdom/ComponentVNode.d.ts.map +1 -1
- package/dist/vdom/ComponentVNode.js +17 -8
- package/dist/vdom/ElementVNode.d.ts +6 -9
- package/dist/vdom/ElementVNode.d.ts.map +1 -1
- package/dist/vdom/ElementVNode.js +103 -34
- package/dist/vdom/FragmentVNode.d.ts +2 -2
- package/dist/vdom/FragmentVNode.d.ts.map +1 -1
- package/dist/vdom/FragmentVNode.js +18 -7
- package/dist/vdom/RootVNode.d.ts +2 -2
- package/dist/vdom/RootVNode.d.ts.map +1 -1
- package/dist/vdom/RootVNode.js +15 -6
- package/dist/vdom/dom-utils.d.ts +6 -1
- package/dist/vdom/dom-utils.d.ts.map +1 -1
- package/dist/vdom/dom-utils.js +20 -1
- package/dist/vdom/types.d.ts +12 -0
- package/dist/vdom/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/component.d.ts +0 -38
- package/dist/component.d.ts.map +0 -1
- package/dist/component.js +0 -130
- package/dist/context.d.ts +0 -5
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -29
- package/dist/createAsync.test.d.ts +0 -2
- package/dist/createAsync.test.d.ts.map +0 -1
- package/dist/createAsync.test.js +0 -110
- package/dist/createAsyncState.d.ts +0 -16
- package/dist/createAsyncState.d.ts.map +0 -1
- package/dist/createAsyncState.js +0 -24
- package/dist/createContext.test.d.ts +0 -2
- package/dist/createContext.test.d.ts.map +0 -1
- package/dist/createContext.test.js +0 -136
- package/dist/createMutation.test.d.ts +0 -2
- package/dist/createMutation.test.d.ts.map +0 -1
- package/dist/createMutation.test.js +0 -168
- package/dist/createQuery.test.d.ts +0 -2
- package/dist/createQuery.test.d.ts.map +0 -1
- package/dist/createQuery.test.js +0 -156
- package/dist/createRef.test.d.ts +0 -2
- package/dist/createRef.test.d.ts.map +0 -1
- package/dist/createRef.test.js +0 -80
- package/dist/createState.test.d.ts +0 -2
- package/dist/createState.test.d.ts.map +0 -1
- package/dist/createState.test.js +0 -111
- package/dist/createView.test.d.ts +0 -2
- package/dist/createView.test.d.ts.map +0 -1
- package/dist/createView.test.js +0 -203
- package/dist/error.test.d.ts +0 -2
- package/dist/error.test.d.ts.map +0 -1
- package/dist/error.test.js +0 -144
- package/dist/integration.test.d.ts +0 -2
- package/dist/integration.test.d.ts.map +0 -1
- package/dist/integration.test.js +0 -155
- package/dist/jsx.d.ts.map +0 -1
- package/dist/jsx.js +0 -42
- package/dist/observation.test.d.ts +0 -2
- package/dist/observation.test.d.ts.map +0 -1
- package/dist/observation.test.js +0 -113
- package/dist/render-test.d.ts +0 -2
- package/dist/render-test.d.ts.map +0 -1
- package/dist/render-test.js +0 -21
- package/dist/render.d.ts +0 -7
- package/dist/render.d.ts.map +0 -1
- package/dist/render.js +0 -77
- package/dist/suspense.d.ts +0 -25
- package/dist/suspense.d.ts.map +0 -1
- package/dist/suspense.js +0 -97
- package/dist/tests/class.test.d.ts +0 -2
- package/dist/tests/class.test.d.ts.map +0 -1
- package/dist/tests/class.test.js +0 -185
- package/dist/tests/complex-rendering.test.d.ts +0 -2
- package/dist/tests/complex-rendering.test.d.ts.map +0 -1
- package/dist/tests/complex-rendering.test.js +0 -400
- package/dist/tests/component.cleanup.test.d.ts +0 -2
- package/dist/tests/component.cleanup.test.d.ts.map +0 -1
- package/dist/tests/component.cleanup.test.js +0 -325
- package/dist/tests/component.counter.test.d.ts +0 -2
- package/dist/tests/component.counter.test.d.ts.map +0 -1
- package/dist/tests/component.counter.test.js +0 -124
- package/dist/tests/component.interaction.test.d.ts +0 -2
- package/dist/tests/component.interaction.test.d.ts.map +0 -1
- package/dist/tests/component.interaction.test.js +0 -73
- package/dist/tests/component.props.test.d.ts +0 -2
- package/dist/tests/component.props.test.d.ts.map +0 -1
- package/dist/tests/component.props.test.js +0 -334
- package/dist/tests/component.return-types.test.d.ts +0 -2
- package/dist/tests/component.return-types.test.d.ts.map +0 -1
- package/dist/tests/component.return-types.test.js +0 -357
- package/dist/tests/component.state.test.d.ts +0 -2
- package/dist/tests/component.state.test.d.ts.map +0 -1
- package/dist/tests/component.state.test.js +0 -135
- package/dist/tests/component.test.d.ts +0 -2
- package/dist/tests/component.test.d.ts.map +0 -1
- package/dist/tests/component.test.js +0 -63
- package/dist/tests/createAsync.test.d.ts +0 -2
- package/dist/tests/createAsync.test.d.ts.map +0 -1
- package/dist/tests/createAsync.test.js +0 -110
- package/dist/tests/createContext.test.d.ts +0 -2
- package/dist/tests/createContext.test.d.ts.map +0 -1
- package/dist/tests/createContext.test.js +0 -141
- package/dist/tests/createMutation.test.d.ts +0 -2
- package/dist/tests/createMutation.test.d.ts.map +0 -1
- package/dist/tests/createMutation.test.js +0 -168
- package/dist/tests/createQuery.test.d.ts +0 -2
- package/dist/tests/createQuery.test.d.ts.map +0 -1
- package/dist/tests/createQuery.test.js +0 -156
- package/dist/tests/createRef.test.d.ts +0 -2
- package/dist/tests/createRef.test.d.ts.map +0 -1
- package/dist/tests/createRef.test.js +0 -84
- package/dist/tests/createState.test.d.ts +0 -2
- package/dist/tests/createState.test.d.ts.map +0 -1
- package/dist/tests/createState.test.js +0 -103
- package/dist/tests/createView.test.d.ts +0 -2
- package/dist/tests/createView.test.d.ts.map +0 -1
- package/dist/tests/createView.test.js +0 -203
- package/dist/tests/edge-cases.test.d.ts +0 -2
- package/dist/tests/edge-cases.test.d.ts.map +0 -1
- package/dist/tests/edge-cases.test.js +0 -637
- package/dist/tests/error-no-boundary.test.d.ts +0 -2
- package/dist/tests/error-no-boundary.test.d.ts.map +0 -1
- package/dist/tests/error-no-boundary.test.js +0 -174
- package/dist/tests/error.test.d.ts +0 -2
- package/dist/tests/error.test.d.ts.map +0 -1
- package/dist/tests/error.test.js +0 -199
- package/dist/tests/fragment.test.d.ts +0 -2
- package/dist/tests/fragment.test.d.ts.map +0 -1
- package/dist/tests/fragment.test.js +0 -618
- package/dist/tests/integration.test.d.ts +0 -2
- package/dist/tests/integration.test.d.ts.map +0 -1
- package/dist/tests/integration.test.js +0 -192
- package/dist/tests/keys.test.d.ts +0 -2
- package/dist/tests/keys.test.d.ts.map +0 -1
- package/dist/tests/keys.test.js +0 -293
- package/dist/tests/mount.test.d.ts +0 -2
- package/dist/tests/mount.test.d.ts.map +0 -1
- package/dist/tests/mount.test.js +0 -91
- package/dist/tests/observation.test.d.ts +0 -2
- package/dist/tests/observation.test.d.ts.map +0 -1
- package/dist/tests/observation.test.js +0 -113
- package/dist/tests/patch.test.d.ts +0 -2
- package/dist/tests/patch.test.d.ts.map +0 -1
- package/dist/tests/patch.test.js +0 -498
- package/dist/tests/patchChildren.test.d.ts +0 -2
- package/dist/tests/patchChildren.test.d.ts.map +0 -1
- package/dist/tests/patchChildren.test.js +0 -405
- package/dist/tests/primitives.test.d.ts +0 -2
- package/dist/tests/primitives.test.d.ts.map +0 -1
- package/dist/tests/primitives.test.js +0 -132
- package/dist/vdom/class.test.d.ts +0 -2
- package/dist/vdom/class.test.d.ts.map +0 -1
- package/dist/vdom/class.test.js +0 -143
- package/dist/vdom/complex-rendering.test.d.ts +0 -2
- package/dist/vdom/complex-rendering.test.d.ts.map +0 -1
- package/dist/vdom/complex-rendering.test.js +0 -400
- package/dist/vdom/component.cleanup.test.d.ts +0 -2
- package/dist/vdom/component.cleanup.test.d.ts.map +0 -1
- package/dist/vdom/component.cleanup.test.js +0 -323
- package/dist/vdom/component.counter.test.d.ts +0 -2
- package/dist/vdom/component.counter.test.d.ts.map +0 -1
- package/dist/vdom/component.counter.test.js +0 -124
- package/dist/vdom/component.interaction.test.d.ts +0 -2
- package/dist/vdom/component.interaction.test.d.ts.map +0 -1
- package/dist/vdom/component.interaction.test.js +0 -73
- package/dist/vdom/component.props.test.d.ts +0 -2
- package/dist/vdom/component.props.test.d.ts.map +0 -1
- package/dist/vdom/component.props.test.js +0 -88
- package/dist/vdom/component.return-types.test.d.ts +0 -2
- package/dist/vdom/component.return-types.test.d.ts.map +0 -1
- package/dist/vdom/component.return-types.test.js +0 -357
- package/dist/vdom/component.state.test.d.ts +0 -2
- package/dist/vdom/component.state.test.d.ts.map +0 -1
- package/dist/vdom/component.state.test.js +0 -129
- package/dist/vdom/component.test.d.ts +0 -2
- package/dist/vdom/component.test.d.ts.map +0 -1
- package/dist/vdom/component.test.js +0 -63
- package/dist/vdom/edge-cases.test.d.ts +0 -2
- package/dist/vdom/edge-cases.test.d.ts.map +0 -1
- package/dist/vdom/edge-cases.test.js +0 -637
- package/dist/vdom/fragment.test.d.ts +0 -2
- package/dist/vdom/fragment.test.d.ts.map +0 -1
- package/dist/vdom/fragment.test.js +0 -618
- package/dist/vdom/keys.test.d.ts +0 -2
- package/dist/vdom/keys.test.d.ts.map +0 -1
- package/dist/vdom/keys.test.js +0 -293
- package/dist/vdom/mount.test.d.ts +0 -2
- package/dist/vdom/mount.test.d.ts.map +0 -1
- package/dist/vdom/mount.test.js +0 -91
- package/dist/vdom/patch.test.d.ts +0 -2
- package/dist/vdom/patch.test.d.ts.map +0 -1
- package/dist/vdom/patch.test.js +0 -498
- package/dist/vdom/patchChildren.test.d.ts +0 -2
- package/dist/vdom/patchChildren.test.d.ts.map +0 -1
- package/dist/vdom/patchChildren.test.js +0 -392
- package/dist/vdom/primitives.test.d.ts +0 -2
- package/dist/vdom/primitives.test.d.ts.map +0 -1
- package/dist/vdom/primitives.test.js +0 -132
package/dist/createView.test.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { createView } from './createView';
|
|
3
|
-
import { createState } from './createState';
|
|
4
|
-
import { Observer } from './observation';
|
|
5
|
-
describe('createView', () => {
|
|
6
|
-
it('should merge two plain objects', () => {
|
|
7
|
-
const a = { x: 1, y: 2 };
|
|
8
|
-
const b = { z: 3 };
|
|
9
|
-
const view = createView(a, b);
|
|
10
|
-
expect(view.x).toBe(1);
|
|
11
|
-
expect(view.y).toBe(2);
|
|
12
|
-
expect(view.z).toBe(3);
|
|
13
|
-
});
|
|
14
|
-
it('should allow later arguments to override earlier ones', () => {
|
|
15
|
-
const a = { x: 1, y: 2 };
|
|
16
|
-
const b = { y: 3, z: 4 };
|
|
17
|
-
const view = createView(a, b);
|
|
18
|
-
expect(view.x).toBe(1);
|
|
19
|
-
expect(view.y).toBe(3); // b.y overrides a.y
|
|
20
|
-
expect(view.z).toBe(4);
|
|
21
|
-
});
|
|
22
|
-
it('should maintain reactivity with reactive objects', async () => {
|
|
23
|
-
const state = createState({ count: 0 });
|
|
24
|
-
const view = createView(state);
|
|
25
|
-
let renderCount = 0;
|
|
26
|
-
let lastValue = 0;
|
|
27
|
-
const observer = new Observer(() => {
|
|
28
|
-
renderCount++;
|
|
29
|
-
});
|
|
30
|
-
const dispose = observer.observe();
|
|
31
|
-
lastValue = view.count; // Track the property
|
|
32
|
-
dispose();
|
|
33
|
-
expect(renderCount).toBe(0);
|
|
34
|
-
state.count = 5;
|
|
35
|
-
// Wait for microtask to process notification
|
|
36
|
-
await new Promise((resolve) => {
|
|
37
|
-
queueMicrotask(() => {
|
|
38
|
-
expect(renderCount).toBe(1);
|
|
39
|
-
lastValue = view.count;
|
|
40
|
-
expect(lastValue).toBe(5);
|
|
41
|
-
resolve(undefined);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
it('should merge reactive and plain objects while maintaining reactivity', () => {
|
|
46
|
-
const state = createState({ count: 0 });
|
|
47
|
-
const helpers = {
|
|
48
|
-
increment() {
|
|
49
|
-
state.count++;
|
|
50
|
-
},
|
|
51
|
-
decrement() {
|
|
52
|
-
state.count--;
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
const view = createView(state, helpers);
|
|
56
|
-
expect(view.count).toBe(0);
|
|
57
|
-
expect(typeof view.increment).toBe('function');
|
|
58
|
-
expect(typeof view.decrement).toBe('function');
|
|
59
|
-
view.increment();
|
|
60
|
-
expect(view.count).toBe(1);
|
|
61
|
-
view.decrement();
|
|
62
|
-
expect(view.count).toBe(0);
|
|
63
|
-
});
|
|
64
|
-
it('should merge multiple reactive objects', () => {
|
|
65
|
-
const state1 = createState({ count: 0 });
|
|
66
|
-
const state2 = createState({ name: 'Alice' });
|
|
67
|
-
const state3 = createState({ age: 25 });
|
|
68
|
-
const view = createView(state1, state2, state3);
|
|
69
|
-
expect(view.count).toBe(0);
|
|
70
|
-
expect(view.name).toBe('Alice');
|
|
71
|
-
expect(view.age).toBe(25);
|
|
72
|
-
state1.count = 10;
|
|
73
|
-
state2.name = 'Bob';
|
|
74
|
-
state3.age = 30;
|
|
75
|
-
expect(view.count).toBe(10);
|
|
76
|
-
expect(view.name).toBe('Bob');
|
|
77
|
-
expect(view.age).toBe(30);
|
|
78
|
-
});
|
|
79
|
-
it('should reflect changes in source objects', () => {
|
|
80
|
-
const source = { x: 1 };
|
|
81
|
-
const view = createView(source);
|
|
82
|
-
expect(view.x).toBe(1);
|
|
83
|
-
source.x = 2;
|
|
84
|
-
expect(view.x).toBe(2);
|
|
85
|
-
});
|
|
86
|
-
it('should handle property override order correctly', () => {
|
|
87
|
-
const a = { x: 1, y: 2, z: 3 };
|
|
88
|
-
const b = { y: 20 };
|
|
89
|
-
const c = { z: 30 };
|
|
90
|
-
const view = createView(a, b, c);
|
|
91
|
-
expect(view.x).toBe(1); // From a
|
|
92
|
-
expect(view.y).toBe(20); // From b (overrides a)
|
|
93
|
-
expect(view.z).toBe(30); // From c (overrides a)
|
|
94
|
-
});
|
|
95
|
-
it('should only include enumerable properties', () => {
|
|
96
|
-
const obj = { x: 1 };
|
|
97
|
-
Object.defineProperty(obj, 'hidden', {
|
|
98
|
-
value: 42,
|
|
99
|
-
enumerable: false,
|
|
100
|
-
});
|
|
101
|
-
const view = createView(obj);
|
|
102
|
-
expect(view.x).toBe(1);
|
|
103
|
-
expect(view.hidden).toBeUndefined();
|
|
104
|
-
});
|
|
105
|
-
it('should handle symbol keys', () => {
|
|
106
|
-
const sym = Symbol('test');
|
|
107
|
-
const obj = { x: 1, [sym]: 'symbol value' };
|
|
108
|
-
const view = createView(obj);
|
|
109
|
-
expect(view.x).toBe(1);
|
|
110
|
-
expect(view[sym]).toBe('symbol value');
|
|
111
|
-
});
|
|
112
|
-
it('should track dependencies for each property independently', async () => {
|
|
113
|
-
const state = createState({ count: 0, name: 'Alice' });
|
|
114
|
-
const view = createView(state);
|
|
115
|
-
let countRenderCount = 0;
|
|
116
|
-
let nameRenderCount = 0;
|
|
117
|
-
// Observer that only accesses count
|
|
118
|
-
const countObserver = new Observer(() => {
|
|
119
|
-
countRenderCount++;
|
|
120
|
-
});
|
|
121
|
-
const dispose1 = countObserver.observe();
|
|
122
|
-
view.count; // Track count
|
|
123
|
-
dispose1();
|
|
124
|
-
expect(countRenderCount).toBe(0);
|
|
125
|
-
// Change count - should trigger
|
|
126
|
-
state.count = 1;
|
|
127
|
-
await new Promise((resolve) => {
|
|
128
|
-
queueMicrotask(() => {
|
|
129
|
-
expect(countRenderCount).toBe(1);
|
|
130
|
-
resolve(undefined);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
// Change name - should NOT trigger (not tracked)
|
|
134
|
-
state.name = 'Bob';
|
|
135
|
-
await new Promise((resolve) => {
|
|
136
|
-
queueMicrotask(() => {
|
|
137
|
-
expect(countRenderCount).toBe(1); // Still 1
|
|
138
|
-
resolve(undefined);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
// Now track name with a different observer
|
|
142
|
-
const nameObserver = new Observer(() => {
|
|
143
|
-
nameRenderCount++;
|
|
144
|
-
});
|
|
145
|
-
const dispose2 = nameObserver.observe();
|
|
146
|
-
view.name; // Track name
|
|
147
|
-
dispose2();
|
|
148
|
-
expect(nameRenderCount).toBe(0);
|
|
149
|
-
// Change name - should trigger name observer
|
|
150
|
-
state.name = 'Charlie';
|
|
151
|
-
await new Promise((resolve) => {
|
|
152
|
-
queueMicrotask(() => {
|
|
153
|
-
expect(nameRenderCount).toBe(1);
|
|
154
|
-
resolve(undefined);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
it('should return the same value type as source', () => {
|
|
159
|
-
const obj = { nums: [1, 2, 3], nested: { x: 1 } };
|
|
160
|
-
const view = createView(obj);
|
|
161
|
-
expect(Array.isArray(view.nums)).toBe(true);
|
|
162
|
-
expect(view.nums).toEqual([1, 2, 3]);
|
|
163
|
-
expect(typeof view.nested).toBe('object');
|
|
164
|
-
expect(view.nested.x).toBe(1);
|
|
165
|
-
});
|
|
166
|
-
it('should handle empty merge', () => {
|
|
167
|
-
const view = createView({});
|
|
168
|
-
expect(Object.keys(view).length).toBe(0);
|
|
169
|
-
});
|
|
170
|
-
it('should merge single object', () => {
|
|
171
|
-
const obj = { x: 1, y: 2 };
|
|
172
|
-
const view = createView(obj);
|
|
173
|
-
expect(view.x).toBe(1);
|
|
174
|
-
expect(view.y).toBe(2);
|
|
175
|
-
});
|
|
176
|
-
it('should maintain function context', () => {
|
|
177
|
-
const state = createState({ count: 0 });
|
|
178
|
-
const methods = {
|
|
179
|
-
increment() {
|
|
180
|
-
state.count++;
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
const view = createView(state, methods);
|
|
184
|
-
expect(view.count).toBe(0);
|
|
185
|
-
view.increment();
|
|
186
|
-
expect(view.count).toBe(1);
|
|
187
|
-
expect(state.count).toBe(1);
|
|
188
|
-
});
|
|
189
|
-
it('should work with reactive state and computed-like patterns', () => {
|
|
190
|
-
const state = createState({ firstName: 'John', lastName: 'Doe' });
|
|
191
|
-
const computed = {
|
|
192
|
-
get fullName() {
|
|
193
|
-
return `${state.firstName} ${state.lastName}`;
|
|
194
|
-
},
|
|
195
|
-
};
|
|
196
|
-
const view = createView(state, computed);
|
|
197
|
-
expect(view.firstName).toBe('John');
|
|
198
|
-
expect(view.lastName).toBe('Doe');
|
|
199
|
-
expect(view.fullName).toBe('John Doe');
|
|
200
|
-
state.firstName = 'Jane';
|
|
201
|
-
expect(view.fullName).toBe('Jane Doe');
|
|
202
|
-
});
|
|
203
|
-
});
|
package/dist/error.test.d.ts
DELETED
package/dist/error.test.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.test.d.ts","sourceRoot":"","sources":["../src/error.test.tsx"],"names":[],"mappings":""}
|
package/dist/error.test.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "./jsx-runtime";
|
|
2
|
-
import { describe, it, expect } from "vitest";
|
|
3
|
-
import { ErrorBoundary } from "./error";
|
|
4
|
-
import { renderComponent } from "./test-setup";
|
|
5
|
-
describe("ErrorBoundary", () => {
|
|
6
|
-
it("should render children when no error occurs", async () => {
|
|
7
|
-
function SafeChild() {
|
|
8
|
-
return () => _jsx("div", { children: "Safe content" });
|
|
9
|
-
}
|
|
10
|
-
function TestComponent() {
|
|
11
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(SafeChild, {}) }));
|
|
12
|
-
}
|
|
13
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
14
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
15
|
-
expect(container.textContent).toContain("Safe content");
|
|
16
|
-
expect(container.textContent).not.toContain("Error:");
|
|
17
|
-
unmount();
|
|
18
|
-
});
|
|
19
|
-
it("should catch errors thrown in child components", async () => {
|
|
20
|
-
function ThrowingChild() {
|
|
21
|
-
return () => {
|
|
22
|
-
throw new Error("Child component error");
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function TestComponent() {
|
|
26
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(ThrowingChild, {}) }));
|
|
27
|
-
}
|
|
28
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
29
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
30
|
-
expect(container.textContent).toContain("Error:");
|
|
31
|
-
expect(container.textContent).toContain("Child component error");
|
|
32
|
-
unmount();
|
|
33
|
-
});
|
|
34
|
-
it("should render custom error UI", async () => {
|
|
35
|
-
function ThrowingChild() {
|
|
36
|
-
return () => {
|
|
37
|
-
throw new Error("Something went wrong");
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function TestComponent() {
|
|
41
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => (_jsxs("div", { class: "error-ui", children: [_jsx("h1", { children: "Oops!" }), _jsx("p", { children: String(error) })] })), children: _jsx(ThrowingChild, {}) }));
|
|
42
|
-
}
|
|
43
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
44
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
45
|
-
const errorUI = document.querySelector(".error-ui");
|
|
46
|
-
expect(errorUI).not.toBeNull();
|
|
47
|
-
expect(errorUI?.querySelector("h1")?.textContent).toBe("Oops!");
|
|
48
|
-
expect(errorUI?.textContent).toContain("Something went wrong");
|
|
49
|
-
unmount();
|
|
50
|
-
});
|
|
51
|
-
it("should handle multiple children", async () => {
|
|
52
|
-
function SafeChild1() {
|
|
53
|
-
return () => _jsx("div", { children: "Child 1" });
|
|
54
|
-
}
|
|
55
|
-
function SafeChild2() {
|
|
56
|
-
return () => _jsx("div", { children: "Child 2" });
|
|
57
|
-
}
|
|
58
|
-
function TestComponent() {
|
|
59
|
-
return () => (_jsxs(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: [_jsx(SafeChild1, {}), _jsx(SafeChild2, {})] }));
|
|
60
|
-
}
|
|
61
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
62
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
63
|
-
expect(container.textContent).toContain("Child 1");
|
|
64
|
-
expect(container.textContent).toContain("Child 2");
|
|
65
|
-
unmount();
|
|
66
|
-
});
|
|
67
|
-
it("should catch errors from nested children", async () => {
|
|
68
|
-
function DeepChild() {
|
|
69
|
-
return () => {
|
|
70
|
-
throw new Error("Deep error");
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function MiddleChild() {
|
|
74
|
-
return () => _jsx(DeepChild, {});
|
|
75
|
-
}
|
|
76
|
-
function TestComponent() {
|
|
77
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Caught: ", String(error)] }), children: _jsx(MiddleChild, {}) }));
|
|
78
|
-
}
|
|
79
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
80
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
81
|
-
expect(container.textContent).toContain("Caught:");
|
|
82
|
-
expect(container.textContent).toContain("Deep error");
|
|
83
|
-
unmount();
|
|
84
|
-
});
|
|
85
|
-
it("should allow nested error boundaries", async () => {
|
|
86
|
-
function ThrowingChild() {
|
|
87
|
-
return () => {
|
|
88
|
-
throw new Error("Inner error");
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function TestComponent() {
|
|
92
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Outer: ", String(error)] }), children: _jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Inner: ", String(error)] }), children: _jsx(ThrowingChild, {}) }) }));
|
|
93
|
-
}
|
|
94
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
95
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
96
|
-
// Inner boundary should catch the error
|
|
97
|
-
expect(container.textContent).toContain("Inner:");
|
|
98
|
-
expect(container.textContent).not.toContain("Outer:");
|
|
99
|
-
unmount();
|
|
100
|
-
});
|
|
101
|
-
it("should handle string errors", async () => {
|
|
102
|
-
function ThrowingChild() {
|
|
103
|
-
return () => {
|
|
104
|
-
throw "String error";
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
function TestComponent() {
|
|
108
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(ThrowingChild, {}) }));
|
|
109
|
-
}
|
|
110
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
111
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
112
|
-
expect(container.textContent).toContain("String error");
|
|
113
|
-
unmount();
|
|
114
|
-
});
|
|
115
|
-
it("should handle object errors", async () => {
|
|
116
|
-
function ThrowingChild() {
|
|
117
|
-
return () => {
|
|
118
|
-
throw { message: "Custom error object", code: 500 };
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function TestComponent() {
|
|
122
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => (_jsxs("div", { children: ["Error: ", error.message, " (Code: ", error.code, ")"] })), children: _jsx(ThrowingChild, {}) }));
|
|
123
|
-
}
|
|
124
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
125
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
126
|
-
expect(container.textContent).toContain("Custom error object");
|
|
127
|
-
expect(container.textContent).toContain("500");
|
|
128
|
-
unmount();
|
|
129
|
-
});
|
|
130
|
-
it("should switch back to children if error is cleared", async () => {
|
|
131
|
-
// Note: This test demonstrates the current behavior
|
|
132
|
-
// In practice, error clearing would require additional implementation
|
|
133
|
-
function SafeChild() {
|
|
134
|
-
return () => _jsx("div", { children: "Safe content" });
|
|
135
|
-
}
|
|
136
|
-
function TestComponent() {
|
|
137
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { children: ["Error: ", String(error)] }), children: _jsx(SafeChild, {}) }));
|
|
138
|
-
}
|
|
139
|
-
const { container, unmount } = renderComponent(_jsx(TestComponent, {}));
|
|
140
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
141
|
-
expect(container.textContent).toContain("Safe content");
|
|
142
|
-
unmount();
|
|
143
|
-
});
|
|
144
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"integration.test.d.ts","sourceRoot":"","sources":["../src/integration.test.tsx"],"names":[],"mappings":""}
|
package/dist/integration.test.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "./jsx-runtime";
|
|
2
|
-
import { describe, it, expect, vi } from "vitest";
|
|
3
|
-
import { onCleanup, onMount } from "./vdom/ComponentVNode";
|
|
4
|
-
import { render } from "./vdom";
|
|
5
|
-
import { createState } from "./createState";
|
|
6
|
-
import { createRef } from "./createRef";
|
|
7
|
-
import { createContext } from "./createContext";
|
|
8
|
-
import { ErrorBoundary } from "./error";
|
|
9
|
-
describe("Integration Tests", () => {
|
|
10
|
-
it("should render a simple component", () => {
|
|
11
|
-
function App() {
|
|
12
|
-
return () => _jsx("div", { children: "Hello World" });
|
|
13
|
-
}
|
|
14
|
-
const container = document.createElement("div");
|
|
15
|
-
document.body.appendChild(container);
|
|
16
|
-
render(_jsx(App, {}), container);
|
|
17
|
-
// After patch, container is replaced, so check body instead
|
|
18
|
-
expect(document.body.textContent).toContain("Hello World");
|
|
19
|
-
});
|
|
20
|
-
it("should handle reactive state updates", async () => {
|
|
21
|
-
function Counter() {
|
|
22
|
-
const state = createState({ count: 0 });
|
|
23
|
-
return () => (_jsxs("div", { children: [_jsxs("span", { children: ["Count: ", state.count] }), _jsx("button", { onClick: () => state.count++, children: "Increment" })] }));
|
|
24
|
-
}
|
|
25
|
-
const container = document.createElement("div");
|
|
26
|
-
document.body.appendChild(container);
|
|
27
|
-
render(_jsx(Counter, {}), container);
|
|
28
|
-
expect(document.body.textContent).toContain("Count: 0");
|
|
29
|
-
// Simulate click
|
|
30
|
-
const button = document.querySelector("button");
|
|
31
|
-
button?.click();
|
|
32
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
33
|
-
expect(document.body.textContent).toContain("Count: 1");
|
|
34
|
-
});
|
|
35
|
-
it("should work with refs", async () => {
|
|
36
|
-
function App() {
|
|
37
|
-
const ref = createRef();
|
|
38
|
-
onMount(() => {
|
|
39
|
-
expect(ref.current).not.toBeNull();
|
|
40
|
-
expect(ref.current?.tagName).toBe("DIV");
|
|
41
|
-
});
|
|
42
|
-
return () => _jsx("div", { ref: ref, children: "Test" });
|
|
43
|
-
}
|
|
44
|
-
const container = document.createElement("div");
|
|
45
|
-
document.body.appendChild(container);
|
|
46
|
-
render(_jsx(App, {}), container);
|
|
47
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
48
|
-
});
|
|
49
|
-
it("should handle context", () => {
|
|
50
|
-
const ThemeContext = createContext();
|
|
51
|
-
function Child() {
|
|
52
|
-
const theme = ThemeContext.get();
|
|
53
|
-
return () => _jsx("div", { class: "child", children: theme.theme });
|
|
54
|
-
}
|
|
55
|
-
function Parent() {
|
|
56
|
-
ThemeContext.inject({ theme: "dark" });
|
|
57
|
-
return () => _jsx(Child, {});
|
|
58
|
-
}
|
|
59
|
-
const container = document.createElement("div");
|
|
60
|
-
document.body.appendChild(container);
|
|
61
|
-
render(_jsx(Parent, {}), container);
|
|
62
|
-
expect(document.body.textContent).toContain("dark");
|
|
63
|
-
});
|
|
64
|
-
it("should handle error boundaries", async () => {
|
|
65
|
-
function ThrowingChild() {
|
|
66
|
-
return () => {
|
|
67
|
-
throw new Error("Test error");
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
function App() {
|
|
71
|
-
return () => (_jsx(ErrorBoundary, { error: (error) => _jsxs("div", { class: "error", children: ["Error: ", String(error)] }), children: _jsx(ThrowingChild, {}) }));
|
|
72
|
-
}
|
|
73
|
-
const container = document.createElement("div");
|
|
74
|
-
document.body.appendChild(container);
|
|
75
|
-
render(_jsx(App, {}), container);
|
|
76
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
77
|
-
const errorDiv = document.querySelector(".error");
|
|
78
|
-
expect(errorDiv).not.toBeNull();
|
|
79
|
-
expect(errorDiv?.textContent).toContain("Test error");
|
|
80
|
-
});
|
|
81
|
-
it("should call onMount and onCleanup", async () => {
|
|
82
|
-
const mountFn = vi.fn();
|
|
83
|
-
const cleanupFn = vi.fn();
|
|
84
|
-
let stateFn;
|
|
85
|
-
function Component() {
|
|
86
|
-
onMount(mountFn);
|
|
87
|
-
onCleanup(cleanupFn);
|
|
88
|
-
return () => _jsx("div", { children: "Test" });
|
|
89
|
-
}
|
|
90
|
-
function App() {
|
|
91
|
-
const state = createState({ show: true });
|
|
92
|
-
stateFn = state;
|
|
93
|
-
return () => (state.show ? _jsx(Component, {}) : _jsx("div", { children: "Empty" }));
|
|
94
|
-
}
|
|
95
|
-
const container = document.createElement("div");
|
|
96
|
-
document.body.appendChild(container);
|
|
97
|
-
render(_jsx(App, {}), container);
|
|
98
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
99
|
-
expect(mountFn).toHaveBeenCalledTimes(1);
|
|
100
|
-
expect(cleanupFn).not.toHaveBeenCalled();
|
|
101
|
-
// Unmount by toggling state to render something else
|
|
102
|
-
stateFn.show = false;
|
|
103
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
104
|
-
expect(cleanupFn).toHaveBeenCalledTimes(1);
|
|
105
|
-
});
|
|
106
|
-
it("should handle nested components", () => {
|
|
107
|
-
function GrandChild() {
|
|
108
|
-
return () => _jsx("span", { children: "GrandChild" });
|
|
109
|
-
}
|
|
110
|
-
function Child() {
|
|
111
|
-
return () => (_jsxs("div", { children: ["Child ", _jsx(GrandChild, {})] }));
|
|
112
|
-
}
|
|
113
|
-
function Parent() {
|
|
114
|
-
return () => (_jsxs("div", { children: ["Parent ", _jsx(Child, {})] }));
|
|
115
|
-
}
|
|
116
|
-
const container = document.createElement("div");
|
|
117
|
-
document.body.appendChild(container);
|
|
118
|
-
render(_jsx(Parent, {}), container);
|
|
119
|
-
expect(document.body.textContent).toContain("Parent");
|
|
120
|
-
expect(document.body.textContent).toContain("Child");
|
|
121
|
-
expect(document.body.textContent).toContain("GrandChild");
|
|
122
|
-
});
|
|
123
|
-
it("should handle conditional rendering", async () => {
|
|
124
|
-
function App() {
|
|
125
|
-
const state = createState({ show: true });
|
|
126
|
-
return () => (_jsxs("div", { children: [_jsx("button", { onClick: () => (state.show = !state.show), children: "Toggle" }), state.show ? _jsx("div", { class: "content", children: "Content" }) : null] }));
|
|
127
|
-
}
|
|
128
|
-
const container = document.createElement("div");
|
|
129
|
-
document.body.appendChild(container);
|
|
130
|
-
render(_jsx(App, {}), container);
|
|
131
|
-
// Wait for initial render
|
|
132
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
133
|
-
expect(document.querySelector(".content")).not.toBeNull();
|
|
134
|
-
const button = document.querySelector("button");
|
|
135
|
-
button?.click();
|
|
136
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
137
|
-
expect(document.querySelector(".content")).toBeNull();
|
|
138
|
-
});
|
|
139
|
-
it("should handle list rendering", async () => {
|
|
140
|
-
function TodoList() {
|
|
141
|
-
const state = createState({ items: ["Item 1", "Item 2"] });
|
|
142
|
-
return () => (_jsxs("div", { children: [_jsx("button", { onClick: () => {
|
|
143
|
-
state.items.push(`Item ${state.items.length + 1}`);
|
|
144
|
-
}, children: "Add" }), _jsx("ul", { children: state.items.map((item) => (_jsx("li", { children: item }))) })] }));
|
|
145
|
-
}
|
|
146
|
-
const container = document.createElement("div");
|
|
147
|
-
document.body.appendChild(container);
|
|
148
|
-
render(_jsx(TodoList, {}), container);
|
|
149
|
-
expect(document.querySelectorAll("li").length).toBe(2);
|
|
150
|
-
const button = document.querySelector("button");
|
|
151
|
-
button?.click();
|
|
152
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
153
|
-
expect(document.querySelectorAll("li").length).toBe(3);
|
|
154
|
-
});
|
|
155
|
-
});
|
package/dist/jsx.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../src/jsx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,wBAAgB,GAAG,CACjB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,QAAQ,EAAE,KAAK,EAAE,SAmDlB"}
|
package/dist/jsx.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { h } from "snabbdom";
|
|
2
|
-
import { createComponent } from "./component";
|
|
3
|
-
export function jsx(type, props, children) {
|
|
4
|
-
let flatChildren = children.flat();
|
|
5
|
-
if (typeof type === "string") {
|
|
6
|
-
const data = {};
|
|
7
|
-
for (const key in props) {
|
|
8
|
-
if (key === "key") {
|
|
9
|
-
data[key] = props[key];
|
|
10
|
-
continue;
|
|
11
|
-
}
|
|
12
|
-
if (key === "hook") {
|
|
13
|
-
data[key] = props[key];
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (key === "style") {
|
|
17
|
-
data.style = props[key];
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
if (key.startsWith("on")) {
|
|
21
|
-
data.on = data.on || {};
|
|
22
|
-
data.on[key.substring(2).toLocaleLowerCase()] = props[key];
|
|
23
|
-
continue;
|
|
24
|
-
}
|
|
25
|
-
if (key.startsWith("data-") || key.startsWith("aria-")) {
|
|
26
|
-
data.attrs = data.attrs || {};
|
|
27
|
-
data.attrs[key] = props[key];
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (type === "svg") {
|
|
31
|
-
data.attrs = data.attrs || {};
|
|
32
|
-
data.attrs[key] = props[key];
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
data.props = data.props || {};
|
|
36
|
-
data.props[key] = props[key];
|
|
37
|
-
}
|
|
38
|
-
return h(type, data, flatChildren);
|
|
39
|
-
}
|
|
40
|
-
const maybeSingleChild = flatChildren.length === 1 ? flatChildren[0] : flatChildren;
|
|
41
|
-
return createComponent(type, props, maybeSingleChild);
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observation.test.d.ts","sourceRoot":"","sources":["../src/observation.test.ts"],"names":[],"mappings":""}
|