@krate/runtime 0.5.0-alpha.4 → 0.5.0-beta.1
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/action-context.d.ts +5 -1
- package/dist/action-context.js +33 -3
- package/dist/action-context.test.js +26 -1
- package/dist/actions.d.ts +12 -1
- package/dist/actions.js +83 -4
- package/dist/actions.test.js +61 -1
- package/dist/cache-scope.js +4 -1
- package/dist/cache.test.js +16 -0
- package/dist/class-helpers.d.ts +4 -4
- package/dist/class-helpers.js +357 -32
- package/dist/class-helpers.test.d.ts +1 -0
- package/dist/class-helpers.test.js +169 -0
- package/dist/context.d.ts +16 -2
- package/dist/context.js +44 -3
- package/dist/dev-overlay.js +75 -2
- package/dist/dev-overlay.test.js +22 -0
- package/dist/dom.d.ts +7 -0
- package/dist/dom.js +69 -3
- package/dist/error-overlay.js +4 -4
- package/dist/hook-args.d.ts +7 -0
- package/dist/hook-args.js +10 -0
- package/dist/htmlspec-attributes.d.ts +1 -0
- package/dist/htmlspec-attributes.js +159 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/krate-core.js +2 -0
- package/dist/krate-dev.js +65 -2
- package/dist/krate-f-actions.js +2 -0
- package/dist/krate-f-classes.js +8 -0
- package/dist/krate-f-helpers.js +2 -0
- package/dist/krate-f-list.js +2 -0
- package/dist/krate-f-router-lite.js +2 -0
- package/dist/krate-f-router.js +2 -0
- package/dist/krate-features.json +239 -0
- package/dist/krate-hydrate-lite.js +5 -5
- package/dist/krate-hydrate.js +5 -5
- package/dist/krate-runtime.js +5 -5
- package/dist/patterns.test.d.ts +1 -0
- package/dist/patterns.test.js +98 -0
- package/dist/reactivity-core.test.d.ts +1 -0
- package/dist/reactivity-core.test.js +152 -0
- package/dist/reconcile.js +4 -2
- package/dist/router-nav.test.js +38 -0
- package/dist/router-speculation.test.d.ts +1 -0
- package/dist/router-speculation.test.js +25 -0
- package/dist/router-styles.test.d.ts +1 -0
- package/dist/router-styles.test.js +98 -0
- package/dist/router.js +116 -32
- package/dist/server-async.test.js +20 -0
- package/dist/server-renderer.js +109 -22
- package/dist/server.d.ts +1 -0
- package/dist/server.js +90 -11
- package/dist/server.test.js +20 -0
- package/dist/signal.d.ts +3 -2
- package/dist/signal.js +104 -19
- package/dist/slots.js +12 -1
- package/package.json +2 -2
package/dist/context.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
let contextId = 0;
|
|
2
2
|
/** Marks Krate context objects so `use(x)` can tell them from promises. */
|
|
3
3
|
export const KRATE_CONTEXT = Symbol.for('krate.context');
|
|
4
|
+
/** A provider value that is read through a getter on every use. */
|
|
5
|
+
class LiveContext {
|
|
6
|
+
constructor(get) {
|
|
7
|
+
this.get = get;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
4
10
|
function toNode(v) {
|
|
5
11
|
if (v instanceof Node)
|
|
6
12
|
return v;
|
|
@@ -27,12 +33,12 @@ export function resetContexts() {
|
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
35
|
* Create a context that carries a CSS scope handle (see {@link CSSScope}). The
|
|
30
|
-
* default is a harmless placeholder
|
|
36
|
+
* default is a harmless placeholder - a `<Provider>` value always wins - so no
|
|
31
37
|
* cast is needed:
|
|
32
38
|
*
|
|
33
39
|
* ```ts
|
|
34
40
|
* const TabsCtx = createScope<string>();
|
|
35
|
-
* // provide: <TabsCtx.Provider value={createCSSChoice('a')}
|
|
41
|
+
* // provide: <TabsCtx.Provider value={createCSSChoice('a')}>...</Provider>
|
|
36
42
|
* // consume: const tab = TabsCtx.use();
|
|
37
43
|
* ```
|
|
38
44
|
*/
|
|
@@ -49,10 +55,18 @@ export function createContext(defaultValue) {
|
|
|
49
55
|
const useContext = () => {
|
|
50
56
|
const stack = contextStack.get(id);
|
|
51
57
|
if (stack && stack.length > 0) {
|
|
52
|
-
|
|
58
|
+
const top = stack[stack.length - 1];
|
|
59
|
+
return (top instanceof LiveContext ? top.get() : top);
|
|
53
60
|
}
|
|
54
61
|
return defaultValue;
|
|
55
62
|
};
|
|
63
|
+
const useContextLive = () => {
|
|
64
|
+
const stack = contextStack.get(id);
|
|
65
|
+
const top = stack && stack.length > 0 ? stack[stack.length - 1] : defaultValue;
|
|
66
|
+
if (top instanceof LiveContext)
|
|
67
|
+
return () => top.get();
|
|
68
|
+
return () => top;
|
|
69
|
+
};
|
|
56
70
|
const Provider = (props) => {
|
|
57
71
|
const stack = contextStack.get(id) || [defaultValue];
|
|
58
72
|
stack.push(props.value);
|
|
@@ -98,5 +112,32 @@ export function createContext(defaultValue) {
|
|
|
98
112
|
ctx.Consumer = Consumer;
|
|
99
113
|
ctx.useContext = useContext;
|
|
100
114
|
ctx.use = useContext;
|
|
115
|
+
ctx.useContextLive = useContextLive;
|
|
101
116
|
return ctx;
|
|
102
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Wraps a list row render function so the provider values of the enclosing
|
|
120
|
+
* `<Ctx.Provider value={...}>` (given as getters over the provider's state)
|
|
121
|
+
* are visible to the rows it creates, and stay live when the state changes.
|
|
122
|
+
* The compiler flattens providers at build time, so rows rendered later by
|
|
123
|
+
* the list runtime have no provider on the stack otherwise.
|
|
124
|
+
*/
|
|
125
|
+
export function krateContextRows(entries, render) {
|
|
126
|
+
return (...args) => {
|
|
127
|
+
const pushed = [];
|
|
128
|
+
for (const [ctx, get] of entries) {
|
|
129
|
+
const stack = contextStack.get(ctx.id);
|
|
130
|
+
if (!stack)
|
|
131
|
+
continue;
|
|
132
|
+
stack.push(new LiveContext(get));
|
|
133
|
+
pushed.push(stack);
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
return render(...args);
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
for (const stack of pushed)
|
|
140
|
+
stack.pop();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
}
|
package/dist/dev-overlay.js
CHANGED
|
@@ -410,18 +410,39 @@ class KrateDev {
|
|
|
410
410
|
catch {
|
|
411
411
|
return;
|
|
412
412
|
}
|
|
413
|
+
let connectedOnce = false;
|
|
414
|
+
sse.addEventListener('connected', () => {
|
|
415
|
+
// A second "connected" means the stream dropped and came back: the dev
|
|
416
|
+
// server restarted (config or env change), so the page is stale.
|
|
417
|
+
if (connectedOnce)
|
|
418
|
+
location.reload();
|
|
419
|
+
connectedOnce = true;
|
|
420
|
+
});
|
|
413
421
|
sse.addEventListener('reload', (e) => {
|
|
422
|
+
// A rebuild without diagnostics supersedes any compile error on screen,
|
|
423
|
+
// whichever route it touched.
|
|
424
|
+
if (this.buildDiags.length > 0) {
|
|
425
|
+
this.buildDiags = [];
|
|
426
|
+
this.setStatus(true);
|
|
427
|
+
this.render();
|
|
428
|
+
}
|
|
429
|
+
let cssOnly = false;
|
|
414
430
|
try {
|
|
415
431
|
const d = JSON.parse(e.data);
|
|
432
|
+
cssOnly = d.cssOnly === true;
|
|
416
433
|
if (d.pages &&
|
|
417
434
|
Array.isArray(d.pages) &&
|
|
418
|
-
!d.pages.some((p) => routeMatches(p, location.pathname, this.cfg.basePath))) {
|
|
435
|
+
!d.pages.some((p) => p === '/404' || p === '/500' || routeMatches(p, location.pathname, this.cfg.basePath))) {
|
|
419
436
|
return;
|
|
420
437
|
}
|
|
421
438
|
}
|
|
422
439
|
catch {
|
|
423
440
|
/* full reload */
|
|
424
441
|
}
|
|
442
|
+
if (cssOnly) {
|
|
443
|
+
this.swapStylesheets().catch(() => location.reload());
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
425
446
|
location.reload();
|
|
426
447
|
});
|
|
427
448
|
sse.addEventListener('build-error', (e) => {
|
|
@@ -441,6 +462,9 @@ class KrateDev {
|
|
|
441
462
|
if (!d.clientError)
|
|
442
463
|
return;
|
|
443
464
|
const err = d.clientError;
|
|
465
|
+
// This tab reported the error itself and already shows it.
|
|
466
|
+
if (this.seen.has(err.message + '|' + (err.stack || '')))
|
|
467
|
+
return;
|
|
444
468
|
this.addRuntime('Runtime Error', err.message, err.stack);
|
|
445
469
|
}
|
|
446
470
|
catch {
|
|
@@ -448,6 +472,55 @@ class KrateDev {
|
|
|
448
472
|
}
|
|
449
473
|
});
|
|
450
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Apply a CSS-only rebuild without a full reload: fetch the freshly built
|
|
477
|
+
* document, add its stylesheet links, and drop the ones it no longer has.
|
|
478
|
+
* Inline <style> changes cannot be diffed safely, so they fall back to a
|
|
479
|
+
* reload (the caller reloads when this rejects).
|
|
480
|
+
*/
|
|
481
|
+
async swapStylesheets() {
|
|
482
|
+
const res = await fetch(location.href, { cache: 'no-store', headers: { Accept: 'text/html' } });
|
|
483
|
+
if (!res.ok)
|
|
484
|
+
throw new Error('fetch failed');
|
|
485
|
+
const next = new DOMParser().parseFromString(await res.text(), 'text/html');
|
|
486
|
+
const inline = (d) => Array.from(d.querySelectorAll('style'))
|
|
487
|
+
.map((el) => el.textContent || '')
|
|
488
|
+
.join('\u0000');
|
|
489
|
+
if (inline(next) !== inline(document))
|
|
490
|
+
throw new Error('inline styles changed');
|
|
491
|
+
const abs = (href) => new URL(href, location.href).href;
|
|
492
|
+
const want = Array.from(next.querySelectorAll('link[rel~="stylesheet"]')).map((l) => abs(l.getAttribute('href') || ''));
|
|
493
|
+
const current = Array.from(document.querySelectorAll('link[rel~="stylesheet"]'));
|
|
494
|
+
const have = new Set(current.map((l) => abs(l.getAttribute('href') || '')));
|
|
495
|
+
const loads = [];
|
|
496
|
+
for (const href of want) {
|
|
497
|
+
if (have.has(href))
|
|
498
|
+
continue;
|
|
499
|
+
const link = document.createElement('link');
|
|
500
|
+
link.rel = 'stylesheet';
|
|
501
|
+
link.href = href;
|
|
502
|
+
loads.push(new Promise((resolve, reject) => {
|
|
503
|
+
link.onload = () => resolve();
|
|
504
|
+
link.onerror = () => reject(new Error('stylesheet failed'));
|
|
505
|
+
}));
|
|
506
|
+
document.head.appendChild(link);
|
|
507
|
+
}
|
|
508
|
+
await Promise.all(loads);
|
|
509
|
+
const keep = new Set(want);
|
|
510
|
+
for (const l of current) {
|
|
511
|
+
if (!keep.has(abs(l.getAttribute('href') || '')))
|
|
512
|
+
l.remove();
|
|
513
|
+
}
|
|
514
|
+
// A same-named stylesheet is cache-busted in place.
|
|
515
|
+
for (const l of current) {
|
|
516
|
+
const href = abs(l.getAttribute('href') || '');
|
|
517
|
+
if (!keep.has(href) || !l.isConnected)
|
|
518
|
+
continue;
|
|
519
|
+
const u = new URL(href);
|
|
520
|
+
u.searchParams.set('_krate', String(Date.now()));
|
|
521
|
+
l.href = u.href;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
451
524
|
captureRuntimeErrors() {
|
|
452
525
|
window.addEventListener('error', (e) => {
|
|
453
526
|
const stack = e.error?.stack || '';
|
|
@@ -481,7 +554,7 @@ class KrateDev {
|
|
|
481
554
|
navigator.sendBeacon(this.cfg.errors, new Blob([body], { type: 'application/json' }));
|
|
482
555
|
}
|
|
483
556
|
else {
|
|
484
|
-
fetch(this.cfg.errors, { method: 'POST', body, headers: { 'Content-Type': 'application/json' }, keepalive: true });
|
|
557
|
+
fetch(this.cfg.errors, { method: 'POST', body, headers: { 'Content-Type': 'application/json' }, keepalive: true }).catch(() => { });
|
|
485
558
|
}
|
|
486
559
|
}
|
|
487
560
|
catch {
|
package/dist/dev-overlay.test.js
CHANGED
|
@@ -20,6 +20,8 @@ let overlay;
|
|
|
20
20
|
// import, and the export is captured from the same module instance.
|
|
21
21
|
beforeAll(async () => {
|
|
22
22
|
globalThis.EventSource = FakeEventSource;
|
|
23
|
+
// Error reports must not reach the (absent) dev server from the test.
|
|
24
|
+
navigator.sendBeacon = () => true;
|
|
23
25
|
window.__KRATE_DEV__ = {
|
|
24
26
|
sse: '/__krate/hotreload',
|
|
25
27
|
errors: '/__krate/client-error',
|
|
@@ -83,6 +85,26 @@ describe('dev-overlay', () => {
|
|
|
83
85
|
expect(overlay.hidden).toBe(true);
|
|
84
86
|
});
|
|
85
87
|
});
|
|
88
|
+
describe('dev-overlay rebuild handling', () => {
|
|
89
|
+
it('clears a build error when a rebuild of another route succeeds', () => {
|
|
90
|
+
history.pushState({}, '', '/current');
|
|
91
|
+
FakeEventSource.last.emit('build-error', { diagnostics: [{ file: 'b.tsx', message: 'stale-build-error' }], buildOk: false });
|
|
92
|
+
const overlayEl = devRoot().querySelector('.overlay');
|
|
93
|
+
expect(overlayEl.hidden).toBe(false);
|
|
94
|
+
expect(devRoot().querySelector('.list').textContent).toContain('stale-build-error');
|
|
95
|
+
// The fix landed on a different route: no reload here, but the error goes.
|
|
96
|
+
FakeEventSource.last.emit('reload', { pages: ['/elsewhere'] });
|
|
97
|
+
const text = devRoot().querySelector('.list').textContent || '';
|
|
98
|
+
expect(text).not.toContain('stale-build-error');
|
|
99
|
+
});
|
|
100
|
+
it('shows a runtime error once when the server echoes it back', () => {
|
|
101
|
+
const before = (devRoot().querySelector('.list').textContent || '').split('echo-dup-error').length - 1;
|
|
102
|
+
window.dispatchEvent(new ErrorEvent('error', { message: 'echo-dup-error', filename: 'x.js', lineno: 1, colno: 1 }));
|
|
103
|
+
FakeEventSource.last.emit('client-error', { clientError: { message: 'echo-dup-error', stack: '' } });
|
|
104
|
+
const text = devRoot().querySelector('.list').textContent || '';
|
|
105
|
+
expect(text.split('echo-dup-error').length - 1 - before).toBe(1);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
86
108
|
describe('routeMatches', () => {
|
|
87
109
|
it('matches unprefixed patterns against a base-path URL', () => {
|
|
88
110
|
expect(overlay.routeMatches('/about', '/docs/about', '/docs')).toBe(true);
|
package/dist/dom.d.ts
CHANGED
|
@@ -47,6 +47,13 @@ export declare function insert(parent: Node, value: unknown, startMarker: Node):
|
|
|
47
47
|
* removed. Other inline styles are left alone.
|
|
48
48
|
*/
|
|
49
49
|
export declare function krateApplyStyle(el: Element, style: Record<string, unknown>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Applies a spread props object (`<input {...field} />`) to el and re-applies
|
|
52
|
+
* it when the state `get` reads changes: attributes, form state, styles and
|
|
53
|
+
* event handlers are set, and keys the previous object had but the new one
|
|
54
|
+
* lacks are removed.
|
|
55
|
+
*/
|
|
56
|
+
export declare function krateSpread(el: Element, get: () => Record<string, unknown> | null | undefined): void;
|
|
50
57
|
/** A deferred element produced by h() while adopting server-rendered DOM. */
|
|
51
58
|
export interface KrateVNode {
|
|
52
59
|
__kv: 1;
|
package/dist/dom.js
CHANGED
|
@@ -268,6 +268,37 @@ function applyProps(el, props) {
|
|
|
268
268
|
el.innerHTML = next;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
|
+
const spreadKeys = new WeakMap();
|
|
272
|
+
/**
|
|
273
|
+
* Applies a spread props object (`<input {...field} />`) to el and re-applies
|
|
274
|
+
* it when the state `get` reads changes: attributes, form state, styles and
|
|
275
|
+
* event handlers are set, and keys the previous object had but the new one
|
|
276
|
+
* lacks are removed.
|
|
277
|
+
*/
|
|
278
|
+
export function krateSpread(el, get) {
|
|
279
|
+
trackEffect(el, createEffect(() => {
|
|
280
|
+
const props = get() || {};
|
|
281
|
+
const next = new Set();
|
|
282
|
+
for (const key of Object.keys(props)) {
|
|
283
|
+
if (key === 'children' || key === 'key' || key === 'dangerouslySetInnerHTML')
|
|
284
|
+
continue;
|
|
285
|
+
next.add(key);
|
|
286
|
+
setAttr(el, key, props[key]);
|
|
287
|
+
}
|
|
288
|
+
const prev = spreadKeys.get(el);
|
|
289
|
+
if (prev) {
|
|
290
|
+
for (const key of prev) {
|
|
291
|
+
if (next.has(key))
|
|
292
|
+
continue;
|
|
293
|
+
if (key.startsWith('on'))
|
|
294
|
+
krateOn(el, key, null);
|
|
295
|
+
else
|
|
296
|
+
setAttr(el, key, undefined);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
spreadKeys.set(el, next);
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
271
302
|
let vnodeDepth = 0;
|
|
272
303
|
/** Evaluate `fn` with h() producing virtual nodes (see KrateVNode). */
|
|
273
304
|
export function withVNodes(fn) {
|
|
@@ -297,8 +328,43 @@ function isVNode(v) {
|
|
|
297
328
|
function isAdoptable(v) {
|
|
298
329
|
return !!v && typeof v === 'object' && v.__ka === 1;
|
|
299
330
|
}
|
|
331
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
332
|
+
// Tags that only exist in SVG. Ambiguous names (a, script, style, title) stay
|
|
333
|
+
// HTML here and are re-created in the SVG namespace when appended to an SVG
|
|
334
|
+
// parent (see adoptSvgChild).
|
|
335
|
+
const SVG_TAGS = new Set([
|
|
336
|
+
'svg', 'g', 'defs', 'symbol', 'use', 'switch', 'desc', 'metadata', 'path', 'circle', 'ellipse', 'line',
|
|
337
|
+
'polygon', 'polyline', 'rect', 'text', 'tspan', 'textPath', 'image', 'foreignObject', 'marker', 'mask',
|
|
338
|
+
'pattern', 'clipPath', 'linearGradient', 'radialGradient', 'stop', 'filter', 'feBlend', 'feColorMatrix',
|
|
339
|
+
'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap',
|
|
340
|
+
'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR',
|
|
341
|
+
'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight',
|
|
342
|
+
'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence', 'animate', 'animateMotion',
|
|
343
|
+
'animateTransform', 'set', 'mpath', 'view',
|
|
344
|
+
]);
|
|
345
|
+
/** Creates an element in the namespace its tag belongs to. */
|
|
346
|
+
function createTagElement(tag) {
|
|
347
|
+
return SVG_TAGS.has(tag) ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
|
|
348
|
+
}
|
|
349
|
+
/** True when a child appended to parent belongs to the SVG namespace. */
|
|
350
|
+
function inSvg(parent) {
|
|
351
|
+
const p = parent;
|
|
352
|
+
return p.namespaceURI === SVG_NS && p.localName !== 'foreignObject';
|
|
353
|
+
}
|
|
354
|
+
/** Re-creates an HTML-namespace element (a, style, title, ...) as SVG. */
|
|
355
|
+
function adoptSvgChild(parent, child) {
|
|
356
|
+
const c = child;
|
|
357
|
+
if (c.nodeType !== 1 || c.namespaceURI === SVG_NS || !inSvg(parent))
|
|
358
|
+
return child;
|
|
359
|
+
const el = document.createElementNS(SVG_NS, c.localName);
|
|
360
|
+
for (const attr of Array.from(c.attributes))
|
|
361
|
+
el.setAttribute(attr.name, attr.value);
|
|
362
|
+
while (c.firstChild)
|
|
363
|
+
el.appendChild(c.firstChild);
|
|
364
|
+
return el;
|
|
365
|
+
}
|
|
300
366
|
function buildElement(tag, props, children) {
|
|
301
|
-
const el =
|
|
367
|
+
const el = createTagElement(tag);
|
|
302
368
|
if (props)
|
|
303
369
|
applyProps(el, props);
|
|
304
370
|
if (!props || !props.dangerouslySetInnerHTML) {
|
|
@@ -330,14 +396,14 @@ export function appendChild(parent, child) {
|
|
|
330
396
|
return;
|
|
331
397
|
}
|
|
332
398
|
if (isVNode(child)) {
|
|
333
|
-
parent.appendChild(materialize(child));
|
|
399
|
+
parent.appendChild(adoptSvgChild(parent, materialize(child)));
|
|
334
400
|
return;
|
|
335
401
|
}
|
|
336
402
|
if (isAdoptable(child)) {
|
|
337
403
|
parent.appendChild(child.mount());
|
|
338
404
|
return;
|
|
339
405
|
}
|
|
340
|
-
parent.appendChild(child instanceof Node ? child : document.createTextNode(String(child)));
|
|
406
|
+
parent.appendChild(child instanceof Node ? adoptSvgChild(parent, child) : document.createTextNode(String(child)));
|
|
341
407
|
}
|
|
342
408
|
/** Move the disposers tracked on one node to another. */
|
|
343
409
|
function retrack(from, to) {
|
package/dist/error-overlay.js
CHANGED
|
@@ -60,16 +60,16 @@ function showError(title, message, stack) {
|
|
|
60
60
|
const overlay = createOverlay();
|
|
61
61
|
const source = stack ? parseStack(stack) : null;
|
|
62
62
|
const sourceLink = source
|
|
63
|
-
? `<div style="${getSourceLinkStyle()}" onclick="navigator.clipboard.writeText('${source.file}:${source.line}:${source.col}')"
|
|
63
|
+
? `<div style="${getSourceLinkStyle()}" onclick="navigator.clipboard.writeText('${source.file}:${source.line}:${source.col}')">[copy] ${source.file}:${source.line}:${source.col}</div>`
|
|
64
64
|
: '';
|
|
65
65
|
overlay.innerHTML = `
|
|
66
66
|
<div style="${getCardStyle()};position:relative;">
|
|
67
|
-
<button style="${getCloseBtnStyle()}" onclick="document.getElementById('krate-error-overlay').remove();window.__krate_overlay_visible=false;"
|
|
68
|
-
<div style="${getTitleStyle()}"
|
|
67
|
+
<button style="${getCloseBtnStyle()}" onclick="document.getElementById('krate-error-overlay').remove();window.__krate_overlay_visible=false;">x Dismiss</button>
|
|
68
|
+
<div style="${getTitleStyle()}">* ${title}</div>
|
|
69
69
|
<div style="${getMessageStyle()}">${escapeHTML(message)}</div>
|
|
70
70
|
${sourceLink}
|
|
71
71
|
${stack ? `<div style="${getStackStyle()}">${escapeHTML(stack)}</div>` : ''}
|
|
72
|
-
<div style="color:#7f8c8d;font-size:11px;margin-top:16px;">Press Esc to dismiss
|
|
72
|
+
<div style="color:#7f8c8d;font-size:11px;margin-top:16px;">Press Esc to dismiss - Edit the file to fix, then the page will auto-reload</div>
|
|
73
73
|
</div>
|
|
74
74
|
`;
|
|
75
75
|
document.body.appendChild(overlay);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a custom hook parameter. A call site passes an argument that reads
|
|
3
|
+
* reactive state as a derived getter (the compiler wraps it), so the hook
|
|
4
|
+
* sees the current value wherever the parameter is read; any other argument
|
|
5
|
+
* is returned as is.
|
|
6
|
+
*/
|
|
7
|
+
export declare function krateParam<T>(value: T | (() => T)): T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isDerivedGetter } from './signal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads a custom hook parameter. A call site passes an argument that reads
|
|
4
|
+
* reactive state as a derived getter (the compiler wraps it), so the hook
|
|
5
|
+
* sees the current value wherever the parameter is read; any other argument
|
|
6
|
+
* is returned as is.
|
|
7
|
+
*/
|
|
8
|
+
export function krateParam(value) {
|
|
9
|
+
return isDerivedGetter(value) ? value() : value;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ATTR_ALIASES: Record<string, string>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Generated from internal/htmlspec/names.go; keep in sync when attributes change.
|
|
2
|
+
// Maps React prop names to the attribute names the compiler emits.
|
|
3
|
+
export const ATTR_ALIASES = {
|
|
4
|
+
"className": "class",
|
|
5
|
+
"htmlFor": "for",
|
|
6
|
+
"acceptCharset": "accept-charset",
|
|
7
|
+
"httpEquiv": "http-equiv",
|
|
8
|
+
"defaultValue": "value",
|
|
9
|
+
"defaultChecked": "checked",
|
|
10
|
+
"accessKey": "accesskey",
|
|
11
|
+
"allowFullScreen": "allowfullscreen",
|
|
12
|
+
"autoCapitalize": "autocapitalize",
|
|
13
|
+
"autoComplete": "autocomplete",
|
|
14
|
+
"autoCorrect": "autocorrect",
|
|
15
|
+
"autoFocus": "autofocus",
|
|
16
|
+
"autoPlay": "autoplay",
|
|
17
|
+
"autoSave": "autosave",
|
|
18
|
+
"cellPadding": "cellpadding",
|
|
19
|
+
"cellSpacing": "cellspacing",
|
|
20
|
+
"charSet": "charset",
|
|
21
|
+
"classID": "classid",
|
|
22
|
+
"colSpan": "colspan",
|
|
23
|
+
"contentEditable": "contenteditable",
|
|
24
|
+
"contextMenu": "contextmenu",
|
|
25
|
+
"controlsList": "controlslist",
|
|
26
|
+
"crossOrigin": "crossorigin",
|
|
27
|
+
"dateTime": "datetime",
|
|
28
|
+
"disablePictureInPicture": "disablepictureinpicture",
|
|
29
|
+
"disableRemotePlayback": "disableremoteplayback",
|
|
30
|
+
"encType": "enctype",
|
|
31
|
+
"enterKeyHint": "enterkeyhint",
|
|
32
|
+
"fetchPriority": "fetchpriority",
|
|
33
|
+
"formAction": "formaction",
|
|
34
|
+
"formEncType": "formenctype",
|
|
35
|
+
"formMethod": "formmethod",
|
|
36
|
+
"formNoValidate": "formnovalidate",
|
|
37
|
+
"formTarget": "formtarget",
|
|
38
|
+
"frameBorder": "frameborder",
|
|
39
|
+
"hrefLang": "hreflang",
|
|
40
|
+
"imageSizes": "imagesizes",
|
|
41
|
+
"imageSrcSet": "imagesrcset",
|
|
42
|
+
"inputMode": "inputmode",
|
|
43
|
+
"itemID": "itemid",
|
|
44
|
+
"itemProp": "itemprop",
|
|
45
|
+
"itemRef": "itemref",
|
|
46
|
+
"itemScope": "itemscope",
|
|
47
|
+
"itemType": "itemtype",
|
|
48
|
+
"keyParams": "keyparams",
|
|
49
|
+
"keyType": "keytype",
|
|
50
|
+
"marginHeight": "marginheight",
|
|
51
|
+
"marginWidth": "marginwidth",
|
|
52
|
+
"maxLength": "maxlength",
|
|
53
|
+
"mediaGroup": "mediagroup",
|
|
54
|
+
"minLength": "minlength",
|
|
55
|
+
"noModule": "nomodule",
|
|
56
|
+
"noValidate": "novalidate",
|
|
57
|
+
"playsInline": "playsinline",
|
|
58
|
+
"popoverTarget": "popovertarget",
|
|
59
|
+
"popoverTargetAction": "popovertargetaction",
|
|
60
|
+
"radioGroup": "radiogroup",
|
|
61
|
+
"readOnly": "readonly",
|
|
62
|
+
"referrerPolicy": "referrerpolicy",
|
|
63
|
+
"rowSpan": "rowspan",
|
|
64
|
+
"spellCheck": "spellcheck",
|
|
65
|
+
"srcDoc": "srcdoc",
|
|
66
|
+
"srcLang": "srclang",
|
|
67
|
+
"srcSet": "srcset",
|
|
68
|
+
"tabIndex": "tabindex",
|
|
69
|
+
"useMap": "usemap",
|
|
70
|
+
"captureAudio": "capture",
|
|
71
|
+
"shadowRootMode": "shadowrootmode",
|
|
72
|
+
"shadowRootClonable": "shadowrootclonable",
|
|
73
|
+
"shadowRootDelegatesFocus": "shadowrootdelegatesfocus",
|
|
74
|
+
"shadowRootSerializable": "shadowrootserializable",
|
|
75
|
+
"accentHeight": "accent-height",
|
|
76
|
+
"alignmentBaseline": "alignment-baseline",
|
|
77
|
+
"arabicForm": "arabic-form",
|
|
78
|
+
"baselineShift": "baseline-shift",
|
|
79
|
+
"capHeight": "cap-height",
|
|
80
|
+
"clipPath": "clip-path",
|
|
81
|
+
"clipRule": "clip-rule",
|
|
82
|
+
"colorInterpolation": "color-interpolation",
|
|
83
|
+
"colorInterpolationFilters": "color-interpolation-filters",
|
|
84
|
+
"colorProfile": "color-profile",
|
|
85
|
+
"colorRendering": "color-rendering",
|
|
86
|
+
"dominantBaseline": "dominant-baseline",
|
|
87
|
+
"enableBackground": "enable-background",
|
|
88
|
+
"fillOpacity": "fill-opacity",
|
|
89
|
+
"fillRule": "fill-rule",
|
|
90
|
+
"floodColor": "flood-color",
|
|
91
|
+
"floodOpacity": "flood-opacity",
|
|
92
|
+
"fontFamily": "font-family",
|
|
93
|
+
"fontSize": "font-size",
|
|
94
|
+
"fontSizeAdjust": "font-size-adjust",
|
|
95
|
+
"fontStretch": "font-stretch",
|
|
96
|
+
"fontStyle": "font-style",
|
|
97
|
+
"fontVariant": "font-variant",
|
|
98
|
+
"fontWeight": "font-weight",
|
|
99
|
+
"glyphName": "glyph-name",
|
|
100
|
+
"glyphOrientationHorizontal": "glyph-orientation-horizontal",
|
|
101
|
+
"glyphOrientationVertical": "glyph-orientation-vertical",
|
|
102
|
+
"horizAdvX": "horiz-adv-x",
|
|
103
|
+
"horizOriginX": "horiz-origin-x",
|
|
104
|
+
"imageRendering": "image-rendering",
|
|
105
|
+
"letterSpacing": "letter-spacing",
|
|
106
|
+
"lightingColor": "lighting-color",
|
|
107
|
+
"markerEnd": "marker-end",
|
|
108
|
+
"markerMid": "marker-mid",
|
|
109
|
+
"markerStart": "marker-start",
|
|
110
|
+
"overlinePosition": "overline-position",
|
|
111
|
+
"overlineThickness": "overline-thickness",
|
|
112
|
+
"paintOrder": "paint-order",
|
|
113
|
+
"panose1": "panose-1",
|
|
114
|
+
"pointerEvents": "pointer-events",
|
|
115
|
+
"renderingIntent": "rendering-intent",
|
|
116
|
+
"shapeRendering": "shape-rendering",
|
|
117
|
+
"stopColor": "stop-color",
|
|
118
|
+
"stopOpacity": "stop-opacity",
|
|
119
|
+
"strikethroughPosition": "strikethrough-position",
|
|
120
|
+
"strikethroughThickness": "strikethrough-thickness",
|
|
121
|
+
"strokeDasharray": "stroke-dasharray",
|
|
122
|
+
"strokeDashoffset": "stroke-dashoffset",
|
|
123
|
+
"strokeLinecap": "stroke-linecap",
|
|
124
|
+
"strokeLinejoin": "stroke-linejoin",
|
|
125
|
+
"strokeMiterlimit": "stroke-miterlimit",
|
|
126
|
+
"strokeOpacity": "stroke-opacity",
|
|
127
|
+
"strokeWidth": "stroke-width",
|
|
128
|
+
"textAnchor": "text-anchor",
|
|
129
|
+
"textDecoration": "text-decoration",
|
|
130
|
+
"textRendering": "text-rendering",
|
|
131
|
+
"transformOrigin": "transform-origin",
|
|
132
|
+
"underlinePosition": "underline-position",
|
|
133
|
+
"underlineThickness": "underline-thickness",
|
|
134
|
+
"unicodeBidi": "unicode-bidi",
|
|
135
|
+
"unicodeRange": "unicode-range",
|
|
136
|
+
"unitsPerEm": "units-per-em",
|
|
137
|
+
"vAlphabetic": "v-alphabetic",
|
|
138
|
+
"vHanging": "v-hanging",
|
|
139
|
+
"vIdeographic": "v-ideographic",
|
|
140
|
+
"vMathematical": "v-mathematical",
|
|
141
|
+
"vectorEffect": "vector-effect",
|
|
142
|
+
"vertAdvY": "vert-adv-y",
|
|
143
|
+
"vertOriginX": "vert-origin-x",
|
|
144
|
+
"vertOriginY": "vert-origin-y",
|
|
145
|
+
"wordSpacing": "word-spacing",
|
|
146
|
+
"writingMode": "writing-mode",
|
|
147
|
+
"xHeight": "x-height",
|
|
148
|
+
"xlinkActuate": "xlink:actuate",
|
|
149
|
+
"xlinkArcrole": "xlink:arcrole",
|
|
150
|
+
"xlinkHref": "xlink:href",
|
|
151
|
+
"xlinkRole": "xlink:role",
|
|
152
|
+
"xlinkShow": "xlink:show",
|
|
153
|
+
"xlinkTitle": "xlink:title",
|
|
154
|
+
"xlinkType": "xlink:type",
|
|
155
|
+
"xmlBase": "xml:base",
|
|
156
|
+
"xmlLang": "xml:lang",
|
|
157
|
+
"xmlSpace": "xml:space",
|
|
158
|
+
"xmlnsXlink": "xmlns:xlink",
|
|
159
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { initRouter, reinitRouter, destroyRouter, navigate, krateRouter, subscri
|
|
|
16
16
|
export type { NavigateOptions, NavigationState } from './router.js';
|
|
17
17
|
export { clsx, cn, cva, twMerge, Slot, cloneElement } from './class-helpers.js';
|
|
18
18
|
export type { ClassValue, CVAConfig } from './class-helpers.js';
|
|
19
|
+
export { krateParam } from './hook-args.js';
|
|
19
20
|
export { createContext, createScope, createScopeFlags, resetContexts } from './context.js';
|
|
20
21
|
export { createResource } from './resource.js';
|
|
21
22
|
export { requestFormReset, getFormStatus, isServerAction, ServerActionError } from './actions.js';
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { krateCondSwap, krateCondDetached, krateCondReset, krateSanitizeAttr, BL
|
|
|
9
9
|
export { Fragment, jsx, jsxs } from './jsx-runtime.js';
|
|
10
10
|
export { initRouter, reinitRouter, destroyRouter, navigate, krateRouter, subscribeNavigation, getNavigationState, getHistoryState, invalidatePrefetchCache, } from './router.js';
|
|
11
11
|
export { clsx, cn, cva, twMerge, Slot, cloneElement } from './class-helpers.js';
|
|
12
|
+
export { krateParam } from './hook-args.js';
|
|
12
13
|
export { createContext, createScope, createScopeFlags, resetContexts } from './context.js';
|
|
13
14
|
export { createResource } from './resource.js';
|
|
14
15
|
export { requestFormReset, getFormStatus, isServerAction, ServerActionError } from './actions.js';
|