@webjsdev/core 0.7.11 → 0.7.13
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/index.d.ts +19 -2
- package/package.json +23 -5
- package/src/context.d.ts +34 -0
- package/src/csp-nonce.d.ts +3 -0
- package/src/directives.d.ts +98 -0
- package/src/lazy-loader.d.ts +2 -0
- package/src/nav.d.ts +4 -0
- package/src/registry.d.ts +11 -0
- package/src/render-client.d.ts +1 -0
- package/src/render-server.d.ts +14 -0
- package/src/router-client.d.ts +10 -0
- package/src/serialize.d.ts +8 -0
- package/src/signal.d.ts +21 -0
- package/src/task.d.ts +33 -0
- package/src/testing.d.ts +9 -0
- package/src/webjs-frame.d.ts +2 -0
- package/src/webjs-stream.d.ts +8 -0
package/index.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export { repeat, isRepeat } from './src/repeat.js';
|
|
|
66
66
|
export { Suspense, isSuspense } from './src/suspense.js';
|
|
67
67
|
export { connectWS } from './src/websocket-client.js';
|
|
68
68
|
export { richFetch } from './src/rich-fetch.js';
|
|
69
|
-
export { enableClientRouter, disableClientRouter } from './src/router-client.js';
|
|
69
|
+
export { enableClientRouter, disableClientRouter, revalidate } from './src/router-client.js';
|
|
70
70
|
|
|
71
71
|
// `navigate` is typed against the generated `Route` union (#258) rather than
|
|
72
72
|
// the JSDoc `string`. Until an app runs `webjs types`, `Route` resolves to
|
|
@@ -74,10 +74,27 @@ export { enableClientRouter, disableClientRouter } from './src/router-client.js'
|
|
|
74
74
|
// tsserver error. The runtime is the same async function in router-client.js.
|
|
75
75
|
import type { Route } from './src/routes.d.ts';
|
|
76
76
|
export function navigate(url: Route, opts?: { replace?: boolean }): Promise<void>;
|
|
77
|
-
|
|
77
|
+
// The full lit-html-parity directive set (mirrors index.js); the per-directive
|
|
78
|
+
// declarations live in src/directives.d.ts. `repeat` is re-exported above.
|
|
79
|
+
export {
|
|
80
|
+
unsafeHTML, isUnsafeHTML, live, isLive, keyed, isKeyed, guard, isGuard,
|
|
81
|
+
templateContent, isTemplateContent, ref, isRef, createRef, cache, isCache,
|
|
82
|
+
until, isUntil, asyncAppend, isAsyncAppend, asyncReplace, isAsyncReplace,
|
|
83
|
+
watch, isWatch,
|
|
84
|
+
} from './src/directives.js';
|
|
78
85
|
export { createContext, ContextProvider, ContextConsumer, ContextRequestEvent } from './src/context.js';
|
|
79
86
|
export { Task, TaskStatus } from './src/task.js';
|
|
80
87
|
|
|
88
|
+
// Signals (the default state primitive, invariant 5), the CSP nonce reader,
|
|
89
|
+
// the wire serializer, and the streaming/frame custom elements. These mirror
|
|
90
|
+
// the index.js runtime re-exports; their declarations live in the matching
|
|
91
|
+
// src/*.d.ts (#388 fixed the index.d.ts drift from index.js).
|
|
92
|
+
export { signal, computed, effect, batch, isSignal, Signal } from './src/signal.js';
|
|
93
|
+
export { cspNonce, setCspNonceProvider } from './src/csp-nonce.js';
|
|
94
|
+
export { stringify, parse, serialize, deserialize } from './src/serialize.js';
|
|
95
|
+
export { WebjsFrame } from './src/webjs-frame.js';
|
|
96
|
+
export { WebjsStream, renderStream } from './src/webjs-stream.js';
|
|
97
|
+
|
|
81
98
|
// Optimistic-mutation helper: set a signal to an expected value immediately,
|
|
82
99
|
// run the action, roll back on a thrown error or a `{ success: false }`
|
|
83
100
|
// ActionResult, keep the value on success. Returns the action's result.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webjsdev/core",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "webjs core runtime - html/css tags, WebComponent base, isomorphic renderers",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -11,37 +11,55 @@
|
|
|
11
11
|
"default": "./dist/webjs-core.js"
|
|
12
12
|
},
|
|
13
13
|
"./directives": {
|
|
14
|
+
"types": "./src/directives.d.ts",
|
|
14
15
|
"source": "./src/directives.js",
|
|
15
16
|
"default": "./dist/webjs-core-browser.js"
|
|
16
17
|
},
|
|
17
18
|
"./context": {
|
|
19
|
+
"types": "./src/context.d.ts",
|
|
18
20
|
"source": "./src/context.js",
|
|
19
21
|
"default": "./dist/webjs-core-browser.js"
|
|
20
22
|
},
|
|
21
23
|
"./task": {
|
|
24
|
+
"types": "./src/task.d.ts",
|
|
22
25
|
"source": "./src/task.js",
|
|
23
26
|
"default": "./dist/webjs-core-browser.js"
|
|
24
27
|
},
|
|
25
28
|
"./client-router": {
|
|
29
|
+
"types": "./src/router-client.d.ts",
|
|
26
30
|
"source": "./src/router-client.js",
|
|
27
31
|
"default": "./dist/webjs-core-browser.js"
|
|
28
32
|
},
|
|
29
33
|
"./lazy-loader": {
|
|
34
|
+
"types": "./src/lazy-loader.d.ts",
|
|
30
35
|
"source": "./src/lazy-loader.js",
|
|
31
36
|
"default": "./dist/webjs-core-lazy-loader.js"
|
|
32
37
|
},
|
|
33
38
|
"./testing": {
|
|
39
|
+
"types": "./src/testing.d.ts",
|
|
34
40
|
"source": "./src/testing.js",
|
|
35
41
|
"default": "./dist/webjs-core-testing.js"
|
|
36
42
|
},
|
|
37
|
-
"./client":
|
|
38
|
-
|
|
43
|
+
"./client": {
|
|
44
|
+
"types": "./src/render-client.d.ts",
|
|
45
|
+
"default": "./src/render-client.js"
|
|
46
|
+
},
|
|
47
|
+
"./server": {
|
|
48
|
+
"types": "./src/render-server.d.ts",
|
|
49
|
+
"default": "./src/render-server.js"
|
|
50
|
+
},
|
|
39
51
|
"./component": {
|
|
40
52
|
"types": "./src/component.d.ts",
|
|
41
53
|
"default": "./src/component.js"
|
|
42
54
|
},
|
|
43
|
-
"./registry":
|
|
44
|
-
|
|
55
|
+
"./registry": {
|
|
56
|
+
"types": "./src/registry.d.ts",
|
|
57
|
+
"default": "./src/registry.js"
|
|
58
|
+
},
|
|
59
|
+
"./signals": {
|
|
60
|
+
"types": "./src/signal.d.ts",
|
|
61
|
+
"default": "./src/signal.js"
|
|
62
|
+
},
|
|
45
63
|
"./package.json": "./package.json"
|
|
46
64
|
},
|
|
47
65
|
"files": [
|
package/src/context.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactiveController, WebComponent } from './component.js';
|
|
2
|
+
|
|
3
|
+
export interface Context<T = unknown> {
|
|
4
|
+
__context__: symbol;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function createContext<T = unknown>(name: string): Context<T>;
|
|
9
|
+
|
|
10
|
+
export class ContextRequestEvent<T = unknown> extends Event {
|
|
11
|
+
context: Context<T>;
|
|
12
|
+
callback: (value: T, unsubscribe?: () => void) => void;
|
|
13
|
+
subscribe: boolean;
|
|
14
|
+
constructor(
|
|
15
|
+
context: Context<T>,
|
|
16
|
+
callback: (value: T, unsubscribe?: () => void) => void,
|
|
17
|
+
subscribe?: boolean,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ContextProvider<T = unknown> implements ReactiveController {
|
|
22
|
+
constructor(host: WebComponent, options: { context: Context<T>; initialValue?: T });
|
|
23
|
+
get value(): T;
|
|
24
|
+
setValue(newValue: T): void;
|
|
25
|
+
hostConnected(): void;
|
|
26
|
+
hostDisconnected(): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class ContextConsumer<T = unknown> implements ReactiveController {
|
|
30
|
+
constructor(host: WebComponent, options: { context: Context<T>; subscribe?: boolean });
|
|
31
|
+
get value(): T | undefined;
|
|
32
|
+
hostConnected(): void;
|
|
33
|
+
hostDisconnected(): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export { repeat, isRepeat } from './repeat.js';
|
|
2
|
+
|
|
3
|
+
export interface UnsafeHTMLDirective {
|
|
4
|
+
_$webjs: 'unsafe-html';
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface LiveDirective<T = unknown> {
|
|
9
|
+
_$webjs: 'live';
|
|
10
|
+
value: T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface KeyedDirective<T = unknown> {
|
|
14
|
+
_$webjs: 'keyed';
|
|
15
|
+
key: unknown;
|
|
16
|
+
value: T;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GuardDirective<T = unknown> {
|
|
20
|
+
_$webjs: 'guard';
|
|
21
|
+
deps: readonly unknown[];
|
|
22
|
+
fn: () => T;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TemplateContentDirective {
|
|
26
|
+
_$webjs: 'template-content';
|
|
27
|
+
template: HTMLTemplateElement | { innerHTML?: string; content?: DocumentFragment };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface RefObject<T extends Element = Element> {
|
|
31
|
+
value: T | undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface RefDirective<T extends Element = Element> {
|
|
35
|
+
_$webjs: 'ref';
|
|
36
|
+
target: RefObject<T> | ((el: T | undefined) => void);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CacheDirective<T = unknown> {
|
|
40
|
+
_$webjs: 'cache';
|
|
41
|
+
value: T;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface UntilDirective {
|
|
45
|
+
_$webjs: 'until';
|
|
46
|
+
args: unknown[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AsyncAppendDirective<T = unknown> {
|
|
50
|
+
_$webjs: 'async-append';
|
|
51
|
+
iterable: AsyncIterable<T>;
|
|
52
|
+
mapper?: (value: T, index: number) => unknown;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface AsyncReplaceDirective<T = unknown> {
|
|
56
|
+
_$webjs: 'async-replace';
|
|
57
|
+
iterable: AsyncIterable<T>;
|
|
58
|
+
mapper?: (value: T, index: number) => unknown;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface WatchDirective<T = unknown> {
|
|
62
|
+
_$webjs: 'watch';
|
|
63
|
+
signal: { get(): T; __isSignal: true };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function unsafeHTML(htmlString: string | null | undefined): UnsafeHTMLDirective;
|
|
67
|
+
export function isUnsafeHTML(x: unknown): x is UnsafeHTMLDirective;
|
|
68
|
+
export function live<T>(value: T): LiveDirective<T>;
|
|
69
|
+
export function isLive(x: unknown): x is LiveDirective;
|
|
70
|
+
export function keyed<T>(key: unknown, template: T): KeyedDirective<T>;
|
|
71
|
+
export function isKeyed(x: unknown): x is KeyedDirective;
|
|
72
|
+
export function guard<T>(deps: readonly unknown[], fn: () => T): GuardDirective<T>;
|
|
73
|
+
export function isGuard(x: unknown): x is GuardDirective;
|
|
74
|
+
export function templateContent(
|
|
75
|
+
template: HTMLTemplateElement | { innerHTML?: string; content?: DocumentFragment },
|
|
76
|
+
): TemplateContentDirective;
|
|
77
|
+
export function isTemplateContent(x: unknown): x is TemplateContentDirective;
|
|
78
|
+
export function ref<T extends Element = Element>(
|
|
79
|
+
refOrCallback: RefObject<T> | ((el: T | undefined) => void),
|
|
80
|
+
): RefDirective<T>;
|
|
81
|
+
export function isRef(x: unknown): x is RefDirective;
|
|
82
|
+
export function createRef<T extends Element = Element>(): RefObject<T>;
|
|
83
|
+
export function cache<T>(value: T): CacheDirective<T>;
|
|
84
|
+
export function isCache(x: unknown): x is CacheDirective;
|
|
85
|
+
export function until(...args: unknown[]): UntilDirective;
|
|
86
|
+
export function isUntil(x: unknown): x is UntilDirective;
|
|
87
|
+
export function asyncAppend<T>(
|
|
88
|
+
iterable: AsyncIterable<T>,
|
|
89
|
+
mapper?: (value: T, index: number) => unknown,
|
|
90
|
+
): AsyncAppendDirective<T>;
|
|
91
|
+
export function isAsyncAppend(x: unknown): x is AsyncAppendDirective;
|
|
92
|
+
export function asyncReplace<T>(
|
|
93
|
+
iterable: AsyncIterable<T>,
|
|
94
|
+
mapper?: (value: T, index: number) => unknown,
|
|
95
|
+
): AsyncReplaceDirective<T>;
|
|
96
|
+
export function isAsyncReplace(x: unknown): x is AsyncReplaceDirective;
|
|
97
|
+
export function watch<T>(sig: { get(): T; __isSignal: true }): WatchDirective<T>;
|
|
98
|
+
export function isWatch(x: unknown): x is WatchDirective;
|
package/src/nav.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { WebComponent } from './component.js';
|
|
2
|
+
|
|
3
|
+
export type WebComponentConstructor = typeof WebComponent;
|
|
4
|
+
|
|
5
|
+
export function register(tag: string, cls: WebComponentConstructor): void;
|
|
6
|
+
export function primeModuleUrl(tag: string, moduleUrl: string): void;
|
|
7
|
+
export function lookup(tag: string): WebComponentConstructor | undefined;
|
|
8
|
+
export function lookupModuleUrl(tag: string): string | undefined;
|
|
9
|
+
export function isLazy(tag: string): boolean;
|
|
10
|
+
export function tagOf(cls: WebComponentConstructor): string | undefined;
|
|
11
|
+
export function allTags(): string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function render(value: unknown, container: Element | DocumentFragment | ShadowRoot): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SuspenseContext {
|
|
2
|
+
pending: { id: string; promise: Promise<unknown> }[];
|
|
3
|
+
nextId: number;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function renderToString(
|
|
7
|
+
value: unknown,
|
|
8
|
+
opts?: { ssr?: boolean; suspenseCtx?: SuspenseContext },
|
|
9
|
+
): Promise<string>;
|
|
10
|
+
|
|
11
|
+
export function renderToStream(
|
|
12
|
+
value: unknown,
|
|
13
|
+
opts?: { ssr?: boolean; suspenseCtx?: SuspenseContext },
|
|
14
|
+
): ReadableStream;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Route } from './routes.js';
|
|
2
|
+
|
|
3
|
+
export function enableClientRouter(): void;
|
|
4
|
+
export function disableClientRouter(): void;
|
|
5
|
+
export function navigate(url: Route, opts?: { replace?: boolean }): Promise<void>;
|
|
6
|
+
export function loadFrame(
|
|
7
|
+
frameEl: Element,
|
|
8
|
+
url: string,
|
|
9
|
+
): Promise<{ ok: boolean; status: number | null; aborted: boolean }>;
|
|
10
|
+
export function revalidate(url?: string): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The webjs wire serializer (rich-type round-trip: Date / Map / Set / BigInt /
|
|
3
|
+
* Error / typed arrays / Blob / File / FormData / Symbols / cycles).
|
|
4
|
+
*/
|
|
5
|
+
export function stringify(value: unknown): Promise<string>;
|
|
6
|
+
export function parse(text: string): unknown;
|
|
7
|
+
export function serialize(value: unknown): Promise<unknown>;
|
|
8
|
+
export function deserialize(value: unknown): unknown;
|
package/src/signal.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SignalState<T = unknown> {
|
|
2
|
+
readonly __isSignal: true;
|
|
3
|
+
get(): T;
|
|
4
|
+
set(value: T): void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SignalComputed<T = unknown> {
|
|
8
|
+
readonly __isSignal: true;
|
|
9
|
+
get(): T;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function batch<T>(fn: () => T): T;
|
|
13
|
+
export function signal<T>(initial: T, options?: Record<string, unknown>): SignalState<T>;
|
|
14
|
+
export function computed<T>(fn: () => T, options?: Record<string, unknown>): SignalComputed<T>;
|
|
15
|
+
export function isSignal(v: unknown): v is SignalState | SignalComputed;
|
|
16
|
+
export function effect(fn: () => void): () => void;
|
|
17
|
+
|
|
18
|
+
export const Signal: {
|
|
19
|
+
State: new <T>(initial: T, options?: Record<string, unknown>) => SignalState<T>;
|
|
20
|
+
Computed: new <T>(fn: () => T, options?: Record<string, unknown>) => SignalComputed<T>;
|
|
21
|
+
};
|
package/src/task.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactiveController, WebComponent } from './component.js';
|
|
2
|
+
|
|
3
|
+
export const TaskStatus: {
|
|
4
|
+
readonly INITIAL: 0;
|
|
5
|
+
readonly PENDING: 1;
|
|
6
|
+
readonly COMPLETE: 2;
|
|
7
|
+
readonly ERROR: 3;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type TaskStatusValue = (typeof TaskStatus)[keyof typeof TaskStatus];
|
|
11
|
+
|
|
12
|
+
export class Task<T = unknown> implements ReactiveController {
|
|
13
|
+
constructor(host: WebComponent, options: {
|
|
14
|
+
task: (...args: any[]) => Promise<T>;
|
|
15
|
+
args?: () => unknown[];
|
|
16
|
+
autoRun?: boolean;
|
|
17
|
+
});
|
|
18
|
+
get status(): TaskStatusValue;
|
|
19
|
+
get value(): T | undefined;
|
|
20
|
+
get error(): unknown;
|
|
21
|
+
run(): Promise<void>;
|
|
22
|
+
abort(): void;
|
|
23
|
+
render(handlers?: {
|
|
24
|
+
initial?: () => unknown;
|
|
25
|
+
pending?: () => unknown;
|
|
26
|
+
complete?: (value: T) => unknown;
|
|
27
|
+
error?: (error: unknown) => unknown;
|
|
28
|
+
}): unknown;
|
|
29
|
+
hostUpdate(): void;
|
|
30
|
+
hostUpdated(): void;
|
|
31
|
+
hostConnected(): void;
|
|
32
|
+
hostDisconnected(): void;
|
|
33
|
+
}
|
package/src/testing.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TemplateResult } from './html.js';
|
|
2
|
+
|
|
3
|
+
export function fixture(template: TemplateResult | string): Promise<Element>;
|
|
4
|
+
export function ssrFixture(template: TemplateResult | string): Promise<Element>;
|
|
5
|
+
export function waitForUpdate(el: Element): Promise<void>;
|
|
6
|
+
export function assertNoA11yViolations(el: Element, opts?: Record<string, unknown>): Promise<void>;
|
|
7
|
+
export function click(el: Element): void;
|
|
8
|
+
export function shadowQuery(el: Element, selector: string): Element | null;
|
|
9
|
+
export function shadowQueryAll(el: Element, selector: string): Element[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** The `<webjs-stream>` element-level update custom element (#248). */
|
|
2
|
+
export class WebjsStream extends HTMLElement {}
|
|
3
|
+
|
|
4
|
+
/** Apply a `<webjs-stream>` payload (string / nodes) into a document. */
|
|
5
|
+
export function renderStream(
|
|
6
|
+
input: string | DocumentFragment | Node,
|
|
7
|
+
doc?: Document,
|
|
8
|
+
): void;
|