@webjsdev/core 0.7.11 → 0.7.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webjsdev/core",
3
- "version": "0.7.11",
3
+ "version": "0.7.12",
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": "./src/render-client.js",
38
- "./server": "./src/render-server.js",
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": "./src/registry.js",
44
- "./signals": "./src/signal.js",
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": [
@@ -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;
@@ -0,0 +1,2 @@
1
+ export function observeLazy(entries: Record<string, string>): void;
2
+ export function observeViewportOnce(el: Element, callback: () => void): () => void;
package/src/nav.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export function notFound(): never;
2
+ export function redirect(url: string, status?: number): never;
3
+ export function isNotFound(e: unknown): boolean;
4
+ export function isRedirect(e: unknown): boolean;
@@ -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,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
+ }
@@ -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[];