@krate/runtime 0.4.0-rc.1 → 0.4.0-rc.3
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/dom.test.d.ts +1 -0
- package/dist/dom.test.js +31 -0
- package/dist/jsx-types.d.ts +21 -0
- package/dist/signal.test.d.ts +1 -0
- package/dist/signal.test.js +68 -0
- package/dist/storage.test.d.ts +1 -0
- package/dist/storage.test.js +46 -0
- package/package.json +7 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/dom.test.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { h, insert } from './dom';
|
|
3
|
+
describe('h', () => {
|
|
4
|
+
it('creates an element with attributes and text', () => {
|
|
5
|
+
const el = h('div', { class: 'box', id: 'x' }, 'hello');
|
|
6
|
+
expect(el.tagName).toBe('DIV');
|
|
7
|
+
expect(el.getAttribute('class')).toBe('box');
|
|
8
|
+
expect(el.id).toBe('x');
|
|
9
|
+
expect(el.textContent).toBe('hello');
|
|
10
|
+
});
|
|
11
|
+
it('sets DOM properties for form controls', () => {
|
|
12
|
+
const input = h('input', { value: 'abc' });
|
|
13
|
+
expect(input.value).toBe('abc');
|
|
14
|
+
});
|
|
15
|
+
it('nests child nodes', () => {
|
|
16
|
+
const child = h('span', null, 'hi');
|
|
17
|
+
const parent = h('div', null, child);
|
|
18
|
+
expect(parent.firstChild).toBe(child);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe('insert', () => {
|
|
22
|
+
it('replaces content between comment markers', () => {
|
|
23
|
+
const parent = document.createElement('div');
|
|
24
|
+
const start = document.createComment('k');
|
|
25
|
+
const end = document.createComment('k');
|
|
26
|
+
parent.append(start, document.createTextNode('old'), end);
|
|
27
|
+
insert(parent, 'new', start);
|
|
28
|
+
expect(parent.textContent).toBe('new');
|
|
29
|
+
expect(parent.textContent.includes('old')).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|
package/dist/jsx-types.d.ts
CHANGED
|
@@ -208,10 +208,13 @@ declare global {
|
|
|
208
208
|
}
|
|
209
209
|
interface HTMLAttributes extends AriaAttributes, ClipboardEventHandler, CompositionEventHandler, FocusEventHandler, FormEventHandler, KeyboardEventHandler, MouseEventHandler, PointerEventHandler, TouchEventHandler, WheelEventHandler, AnimationEventHandler, TransitionEventHandler, UIEventHandler, MediaEventHandler, DOMAttributes {
|
|
210
210
|
accessKey?: string;
|
|
211
|
+
accesskey?: string;
|
|
211
212
|
class?: string;
|
|
212
213
|
className?: string;
|
|
213
214
|
contentEditable?: Booleanish | 'inherit' | 'false' | 'true';
|
|
215
|
+
contenteditable?: Booleanish | 'inherit' | 'false' | 'true';
|
|
214
216
|
contextMenu?: string;
|
|
217
|
+
contextmenu?: string;
|
|
215
218
|
dir?: string;
|
|
216
219
|
draggable?: Booleanish;
|
|
217
220
|
hidden?: boolean | string;
|
|
@@ -222,6 +225,7 @@ declare global {
|
|
|
222
225
|
role?: string;
|
|
223
226
|
spellcheck?: Booleanish;
|
|
224
227
|
tabIndex?: number;
|
|
228
|
+
tabindex?: number;
|
|
225
229
|
title?: string;
|
|
226
230
|
translate?: 'yes' | 'no';
|
|
227
231
|
about?: string;
|
|
@@ -363,13 +367,16 @@ declare global {
|
|
|
363
367
|
accept?: string;
|
|
364
368
|
alt?: string;
|
|
365
369
|
autoComplete?: string;
|
|
370
|
+
autocomplete?: string;
|
|
366
371
|
autoFocus?: boolean;
|
|
372
|
+
autofocus?: boolean;
|
|
367
373
|
capture?: boolean | string;
|
|
368
374
|
checked?: boolean | string;
|
|
369
375
|
crossOrigin?: string;
|
|
370
376
|
disabled?: boolean | string;
|
|
371
377
|
form?: string;
|
|
372
378
|
formAction?: string;
|
|
379
|
+
formaction?: string;
|
|
373
380
|
formEncType?: string;
|
|
374
381
|
formMethod?: string;
|
|
375
382
|
formNoValidate?: boolean;
|
|
@@ -378,13 +385,16 @@ declare global {
|
|
|
378
385
|
list?: string;
|
|
379
386
|
max?: number | string;
|
|
380
387
|
maxLength?: number;
|
|
388
|
+
maxlength?: number;
|
|
381
389
|
min?: number | string;
|
|
382
390
|
minLength?: number;
|
|
391
|
+
minlength?: number;
|
|
383
392
|
multiple?: boolean;
|
|
384
393
|
name?: string;
|
|
385
394
|
pattern?: string;
|
|
386
395
|
placeholder?: string;
|
|
387
396
|
readOnly?: boolean;
|
|
397
|
+
readonly?: boolean;
|
|
388
398
|
required?: boolean | string;
|
|
389
399
|
size?: number;
|
|
390
400
|
src?: string;
|
|
@@ -403,7 +413,9 @@ declare global {
|
|
|
403
413
|
}
|
|
404
414
|
interface SelectHTMLAttributes extends Omit<HTMLAttributes, 'onChange'> {
|
|
405
415
|
autoComplete?: string;
|
|
416
|
+
autocomplete?: string;
|
|
406
417
|
autoFocus?: boolean;
|
|
418
|
+
autofocus?: boolean;
|
|
407
419
|
disabled?: boolean | string;
|
|
408
420
|
form?: string;
|
|
409
421
|
multiple?: boolean;
|
|
@@ -418,16 +430,21 @@ declare global {
|
|
|
418
430
|
}
|
|
419
431
|
interface TextareaHTMLAttributes extends Omit<HTMLAttributes, 'onChange' | 'onInput'> {
|
|
420
432
|
autoComplete?: string;
|
|
433
|
+
autocomplete?: string;
|
|
421
434
|
autoFocus?: boolean;
|
|
435
|
+
autofocus?: boolean;
|
|
422
436
|
cols?: number;
|
|
423
437
|
dirName?: string;
|
|
424
438
|
disabled?: boolean | string;
|
|
425
439
|
form?: string;
|
|
426
440
|
maxLength?: number;
|
|
441
|
+
maxlength?: number;
|
|
427
442
|
minLength?: number;
|
|
443
|
+
minlength?: number;
|
|
428
444
|
name?: string;
|
|
429
445
|
placeholder?: string;
|
|
430
446
|
readOnly?: boolean;
|
|
447
|
+
readonly?: boolean;
|
|
431
448
|
required?: boolean | string;
|
|
432
449
|
rows?: number;
|
|
433
450
|
value?: string | number;
|
|
@@ -612,8 +629,10 @@ declare global {
|
|
|
612
629
|
}
|
|
613
630
|
interface TdHTMLAttributes extends HTMLAttributes {
|
|
614
631
|
colSpan?: number;
|
|
632
|
+
colspan?: number;
|
|
615
633
|
headers?: string;
|
|
616
634
|
rowSpan?: number;
|
|
635
|
+
rowspan?: number;
|
|
617
636
|
scope?: string;
|
|
618
637
|
abbr?: string;
|
|
619
638
|
width?: number | string;
|
|
@@ -621,8 +640,10 @@ declare global {
|
|
|
621
640
|
interface ThHTMLAttributes extends HTMLAttributes {
|
|
622
641
|
abbr?: string;
|
|
623
642
|
colSpan?: number;
|
|
643
|
+
colspan?: number;
|
|
624
644
|
headers?: string;
|
|
625
645
|
rowSpan?: number;
|
|
646
|
+
rowspan?: number;
|
|
626
647
|
scope?: 'col' | 'colgroup' | 'row' | 'rowgroup';
|
|
627
648
|
width?: number | string;
|
|
628
649
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { createSignal, createEffect, createMemo, onCleanup, disposeAll, } from './signal';
|
|
3
|
+
const flush = () => new Promise((r) => setTimeout(r, 0));
|
|
4
|
+
describe('createSignal', () => {
|
|
5
|
+
beforeEach(() => disposeAll());
|
|
6
|
+
it('reads and writes values', () => {
|
|
7
|
+
const [n, setN] = createSignal(1);
|
|
8
|
+
expect(n()).toBe(1);
|
|
9
|
+
setN(2);
|
|
10
|
+
expect(n()).toBe(2);
|
|
11
|
+
setN((p) => p + 3);
|
|
12
|
+
expect(n()).toBe(5);
|
|
13
|
+
});
|
|
14
|
+
it('does not notify when the value is unchanged', async () => {
|
|
15
|
+
const [n, setN] = createSignal(1);
|
|
16
|
+
let runs = 0;
|
|
17
|
+
createEffect(() => {
|
|
18
|
+
n();
|
|
19
|
+
runs++;
|
|
20
|
+
});
|
|
21
|
+
await flush();
|
|
22
|
+
const before = runs;
|
|
23
|
+
setN(1);
|
|
24
|
+
await flush();
|
|
25
|
+
expect(runs).toBe(before);
|
|
26
|
+
});
|
|
27
|
+
it('runs dependent effects with the new value', async () => {
|
|
28
|
+
const [n, setN] = createSignal(0);
|
|
29
|
+
let seen = -1;
|
|
30
|
+
createEffect(() => {
|
|
31
|
+
seen = n();
|
|
32
|
+
});
|
|
33
|
+
setN(7);
|
|
34
|
+
await flush();
|
|
35
|
+
expect(seen).toBe(7);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
describe('createMemo', () => {
|
|
39
|
+
beforeEach(() => disposeAll());
|
|
40
|
+
it('caches until a dependency changes', async () => {
|
|
41
|
+
const [n, setN] = createSignal(2);
|
|
42
|
+
let computations = 0;
|
|
43
|
+
const doubled = createMemo(() => {
|
|
44
|
+
computations++;
|
|
45
|
+
return n() * 2;
|
|
46
|
+
});
|
|
47
|
+
await flush();
|
|
48
|
+
expect(doubled()).toBe(4);
|
|
49
|
+
expect(doubled()).toBe(4);
|
|
50
|
+
expect(computations).toBe(1);
|
|
51
|
+
setN(5);
|
|
52
|
+
await flush();
|
|
53
|
+
expect(doubled()).toBe(10);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('onCleanup / disposeAll', () => {
|
|
57
|
+
it('runs cleanups when the world is disposed', async () => {
|
|
58
|
+
let cleaned = false;
|
|
59
|
+
createEffect(() => {
|
|
60
|
+
onCleanup(() => {
|
|
61
|
+
cleaned = true;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
await flush();
|
|
65
|
+
disposeAll();
|
|
66
|
+
expect(cleaned).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { resolvePersist, readPersisted, writePersisted, clearPersisted, readDurableState, } from './storage';
|
|
3
|
+
function memory() {
|
|
4
|
+
const map = new Map();
|
|
5
|
+
return {
|
|
6
|
+
getItem: (k) => (map.has(k) ? map.get(k) : null),
|
|
7
|
+
setItem: (k, v) => void map.set(k, v),
|
|
8
|
+
removeItem: (k) => void map.delete(k),
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
describe('persisted signals', () => {
|
|
12
|
+
it('writes and reads through the configured store', () => {
|
|
13
|
+
const store = memory();
|
|
14
|
+
const p = resolvePersist({ key: 'count', store });
|
|
15
|
+
writePersisted(p, 41);
|
|
16
|
+
expect(readPersisted(p)).toEqual({ found: true, value: 41 });
|
|
17
|
+
clearPersisted(p);
|
|
18
|
+
expect(readPersisted(p).found).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
it('accepts a bare key spec', () => {
|
|
21
|
+
const p = resolvePersist('obj');
|
|
22
|
+
expect(p.key).toBe('obj');
|
|
23
|
+
expect(p.store).toBe('local');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
describe('readDurableState', () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
delete globalThis.__KRATE_STATE__;
|
|
29
|
+
});
|
|
30
|
+
it('prefers the durable value, including plain strings', () => {
|
|
31
|
+
globalThis.__KRATE_STATE__ =
|
|
32
|
+
{ count: 5, theme: 'dark' };
|
|
33
|
+
expect(readDurableState('count', JSON.parse)).toEqual({
|
|
34
|
+
found: true,
|
|
35
|
+
value: 5,
|
|
36
|
+
});
|
|
37
|
+
// "dark" is the plain value, not JSON; the fallback must still return it.
|
|
38
|
+
expect(readDurableState('theme', JSON.parse)).toEqual({
|
|
39
|
+
found: true,
|
|
40
|
+
value: 'dark',
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('reports absent keys', () => {
|
|
44
|
+
expect(readDurableState('missing', JSON.parse).found).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krate/runtime",
|
|
3
|
-
"version": "0.4.0-rc.
|
|
3
|
+
"version": "0.4.0-rc.3",
|
|
4
4
|
"description": "Client-side runtime for Krate — signals, hydration, SPA router, resources, and context.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -57,10 +57,14 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/node": "^26.2.0",
|
|
59
59
|
"esbuild": "^0.28.0",
|
|
60
|
-
"
|
|
60
|
+
"happy-dom": "^20.14.5",
|
|
61
|
+
"typescript": "^5.5.0",
|
|
62
|
+
"vitest": "^5.0.3"
|
|
61
63
|
},
|
|
62
64
|
"scripts": {
|
|
63
65
|
"build": "tsc && node bundle.cjs",
|
|
64
|
-
"dev": "tsc --watch"
|
|
66
|
+
"dev": "tsc --watch",
|
|
67
|
+
"test": "vitest run",
|
|
68
|
+
"typecheck": "tsc --noEmit"
|
|
65
69
|
}
|
|
66
70
|
}
|