@manyducks.co/dolla 0.78.2 → 1.0.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/README.md +241 -25
- package/lib/classes/DebugHub.d.ts +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +606 -428
- package/lib/index.js.map +4 -4
- package/lib/markup.d.ts +17 -9
- package/lib/nodes/cond.d.ts +3 -3
- package/lib/nodes/html.d.ts +1 -1
- package/lib/nodes/observer.d.ts +3 -3
- package/lib/nodes/outlet.d.ts +3 -3
- package/lib/nodes/repeat.d.ts +9 -7
- package/lib/nodes/text.d.ts +3 -3
- package/lib/signals.d.ts +118 -0
- package/lib/signals.test.d.ts +1 -0
- package/lib/state.d.ts +3 -2
- package/lib/store.d.ts +2 -19
- package/lib/stores/dialog.d.ts +16 -14
- package/lib/stores/document.d.ts +5 -4
- package/lib/stores/language.d.ts +4 -4
- package/lib/stores/router.d.ts +5 -4
- package/lib/testing/makeMockFetch._test.d.ts +1 -0
- package/lib/testing/makeMockFetch.test_skip.d.ts +1 -0
- package/lib/testing/wrapStore._test.d.ts +1 -0
- package/lib/testing/wrapStore.test_skip.d.ts +1 -0
- package/lib/types.d.ts +16 -32
- package/lib/view.d.ts +18 -19
- package/notes/scratch.md +76 -0
- package/package.json +1 -1
- package/tests/signals.test.js +135 -0
- package/tests/state.test.js +0 -290
package/lib/markup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "./app.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Signal, MaybeSignal } from "./signals.js";
|
|
3
3
|
import type { Renderable, Stringable } from "./types.js";
|
|
4
4
|
import { type View, type ViewContext, type ViewResult } from "./view.js";
|
|
5
5
|
/**
|
|
@@ -25,24 +25,24 @@ export declare function isDOMHandle(value: unknown): value is DOMHandle;
|
|
|
25
25
|
export declare function toMarkup(renderables: Renderable | Renderable[]): Markup[];
|
|
26
26
|
export interface MarkupAttributes {
|
|
27
27
|
$text: {
|
|
28
|
-
value:
|
|
28
|
+
value: MaybeSignal<Stringable>;
|
|
29
29
|
};
|
|
30
30
|
$cond: {
|
|
31
|
-
$predicate:
|
|
31
|
+
$predicate: Signal<any>;
|
|
32
32
|
thenContent?: Renderable;
|
|
33
33
|
elseContent?: Renderable;
|
|
34
34
|
};
|
|
35
35
|
$repeat: {
|
|
36
|
-
$items:
|
|
36
|
+
$items: Signal<any[]>;
|
|
37
37
|
keyFn: (value: any, index: number) => string | number | symbol;
|
|
38
|
-
renderFn: ($item:
|
|
38
|
+
renderFn: ($item: Signal<any>, $index: Signal<number>, c: ViewContext) => ViewResult;
|
|
39
39
|
};
|
|
40
40
|
$observer: {
|
|
41
|
-
|
|
41
|
+
signals: Signal<any>[];
|
|
42
42
|
renderFn: (...items: any) => Renderable;
|
|
43
43
|
};
|
|
44
44
|
$outlet: {
|
|
45
|
-
$children:
|
|
45
|
+
$children: Signal<DOMHandle[]>;
|
|
46
46
|
};
|
|
47
47
|
$node: {
|
|
48
48
|
value: Node;
|
|
@@ -58,16 +58,24 @@ export declare function m<I>(type: View<I>, attributes?: I, ...children: Rendera
|
|
|
58
58
|
/**
|
|
59
59
|
* Displays content conditionally. When `predicate` holds a truthy value, `thenContent` is displayed; when `predicate` holds a falsy value, `elseContent` is displayed.
|
|
60
60
|
*/
|
|
61
|
-
export declare function cond(predicate:
|
|
61
|
+
export declare function cond(predicate: MaybeSignal<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
62
62
|
/**
|
|
63
63
|
* Calls `renderFn` for each item in `items`. Dynamically adds and removes views as items change.
|
|
64
64
|
* The result of `keyFn` is used to compare items and decide if item was added, removed or updated.
|
|
65
65
|
*/
|
|
66
|
-
export declare function repeat<T>(items:
|
|
66
|
+
export declare function repeat<T>(items: MaybeSignal<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: ($value: Signal<T>, $index: Signal<number>, ctx: ViewContext) => ViewResult): Markup;
|
|
67
67
|
/**
|
|
68
68
|
* Render `content` into a `parent` node anywhere in the page, rather than at its position in the view.
|
|
69
69
|
*/
|
|
70
70
|
export declare function portal(content: Renderable, parent: Node): Markup;
|
|
71
|
+
/**
|
|
72
|
+
* A special kind of signal exclusively for storing references to DOM nodes.
|
|
73
|
+
*/
|
|
74
|
+
export declare function ref<T extends Node>(): Ref<T>;
|
|
75
|
+
export declare function isRef<T extends Node>(value: any): value is Ref<T>;
|
|
76
|
+
export interface Ref<T extends Node> extends Signal<T | undefined> {
|
|
77
|
+
node: T | undefined;
|
|
78
|
+
}
|
|
71
79
|
interface RenderContext {
|
|
72
80
|
appContext: AppContext;
|
|
73
81
|
elementContext: ElementContext;
|
package/lib/nodes/cond.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle, type Markup } from "../markup.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Signal, type StopFunction } from "../signals.js";
|
|
4
4
|
import { type Renderable } from "../types.js";
|
|
5
5
|
export interface ConditionalConfig {
|
|
6
|
-
$predicate:
|
|
6
|
+
$predicate: Signal<any>;
|
|
7
7
|
thenContent?: Renderable;
|
|
8
8
|
elseContent?: Renderable;
|
|
9
9
|
appContext: AppContext;
|
|
@@ -12,7 +12,7 @@ export interface ConditionalConfig {
|
|
|
12
12
|
export declare class Conditional implements DOMHandle {
|
|
13
13
|
node: Node;
|
|
14
14
|
endNode: Node;
|
|
15
|
-
$predicate:
|
|
15
|
+
$predicate: Signal<any>;
|
|
16
16
|
stopCallback?: StopFunction;
|
|
17
17
|
thenContent?: Markup[];
|
|
18
18
|
elseContent?: Markup[];
|
package/lib/nodes/html.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle, type Markup } from "../markup.js";
|
|
3
|
-
import { type StopFunction } from "../
|
|
3
|
+
import { type StopFunction } from "../signals.js";
|
|
4
4
|
type HTMLOptions = {
|
|
5
5
|
appContext: AppContext;
|
|
6
6
|
elementContext: ElementContext;
|
package/lib/nodes/observer.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle } from "../markup.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Signal } from "../signals.js";
|
|
4
4
|
import type { Renderable } from "../types.js";
|
|
5
5
|
interface ObserverOptions {
|
|
6
6
|
appContext: AppContext;
|
|
7
7
|
elementContext: ElementContext;
|
|
8
|
-
|
|
8
|
+
signals: Signal<any>[];
|
|
9
9
|
renderFn: (...values: any) => Renderable;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -23,7 +23,7 @@ export declare class Observer implements DOMHandle {
|
|
|
23
23
|
stop: () => void;
|
|
24
24
|
};
|
|
25
25
|
get connected(): boolean;
|
|
26
|
-
constructor({
|
|
26
|
+
constructor({ signals, renderFn, appContext, elementContext }: ObserverOptions);
|
|
27
27
|
connect(parent: Node, after?: Node): void;
|
|
28
28
|
disconnect(): void;
|
|
29
29
|
setChildren(): Promise<void>;
|
package/lib/nodes/outlet.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle } from "../markup.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Signal, type StopFunction } from "../signals.js";
|
|
4
4
|
export interface OutletConfig {
|
|
5
|
-
$children:
|
|
5
|
+
$children: Signal<DOMHandle[]>;
|
|
6
6
|
appContext: AppContext;
|
|
7
7
|
elementContext: ElementContext;
|
|
8
8
|
}
|
|
@@ -12,7 +12,7 @@ export interface OutletConfig {
|
|
|
12
12
|
export declare class Outlet implements DOMHandle {
|
|
13
13
|
node: Node;
|
|
14
14
|
endNode: Node;
|
|
15
|
-
$children:
|
|
15
|
+
$children: Signal<DOMHandle[]>;
|
|
16
16
|
stopCallback?: StopFunction;
|
|
17
17
|
connectedChildren: DOMHandle[];
|
|
18
18
|
appContext: AppContext;
|
package/lib/nodes/repeat.d.ts
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle } from "../markup.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type Signal, type SignalSetter, type StopFunction } from "../signals.js";
|
|
4
4
|
import { type ViewContext, type ViewResult } from "../view.js";
|
|
5
5
|
interface RepeatOptions<T> {
|
|
6
6
|
appContext: AppContext;
|
|
7
7
|
elementContext: ElementContext;
|
|
8
|
-
$items:
|
|
8
|
+
$items: Signal<T[]>;
|
|
9
9
|
keyFn: (value: T, index: number) => string | number | symbol;
|
|
10
|
-
renderFn: ($value:
|
|
10
|
+
renderFn: ($value: Signal<T>, $index: Signal<number>, ctx: ViewContext) => ViewResult;
|
|
11
11
|
}
|
|
12
12
|
type ConnectedItem<T> = {
|
|
13
13
|
key: any;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
$value: Signal<T>;
|
|
15
|
+
setValue: SignalSetter<T>;
|
|
16
|
+
$index: Signal<number>;
|
|
17
|
+
setIndex: SignalSetter<number>;
|
|
16
18
|
handle: DOMHandle;
|
|
17
19
|
};
|
|
18
20
|
export declare class Repeat<T> implements DOMHandle {
|
|
19
21
|
node: Node;
|
|
20
22
|
endNode: Node;
|
|
21
|
-
$items:
|
|
23
|
+
$items: Signal<T[]>;
|
|
22
24
|
stopCallback?: StopFunction;
|
|
23
25
|
connectedItems: ConnectedItem<T>[];
|
|
24
26
|
appContext: AppContext;
|
|
25
27
|
elementContext: ElementContext;
|
|
26
|
-
renderFn: ($value:
|
|
28
|
+
renderFn: ($value: Signal<T>, $index: Signal<number>, ctx: ViewContext) => ViewResult;
|
|
27
29
|
keyFn: (value: T, index: number) => string | number | symbol;
|
|
28
30
|
get connected(): boolean;
|
|
29
31
|
constructor({ appContext, elementContext, $items, renderFn, keyFn }: RepeatOptions<T>);
|
package/lib/nodes/text.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { type DOMHandle } from "../markup.js";
|
|
2
|
-
import {
|
|
2
|
+
import { MaybeSignal, type StopFunction } from "../signals.js";
|
|
3
3
|
interface Stringable {
|
|
4
4
|
toString(): string;
|
|
5
5
|
}
|
|
6
6
|
interface TextOptions {
|
|
7
|
-
value:
|
|
7
|
+
value: MaybeSignal<Stringable>;
|
|
8
8
|
}
|
|
9
9
|
export declare class Text implements DOMHandle {
|
|
10
10
|
node: globalThis.Text;
|
|
11
|
-
value:
|
|
11
|
+
value: MaybeSignal<Stringable>;
|
|
12
12
|
stopCallback?: StopFunction;
|
|
13
13
|
get connected(): boolean;
|
|
14
14
|
constructor({ value }: TextOptions);
|
package/lib/signals.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stops the observer that created it when called.
|
|
3
|
+
*/
|
|
4
|
+
export type StopFunction = () => void;
|
|
5
|
+
type Unwrapped<T> = T extends Signal<infer V> ? V : T;
|
|
6
|
+
/**
|
|
7
|
+
* Extracts value types from an array of signals.
|
|
8
|
+
*/
|
|
9
|
+
export type SignalValues<T extends MaybeSignal<any>[]> = {
|
|
10
|
+
[K in keyof T]: Unwrapped<T[K]>;
|
|
11
|
+
};
|
|
12
|
+
export interface SignalCreateOptions<T> {
|
|
13
|
+
/**
|
|
14
|
+
* Determines if the `next` value is equal to the `previous` value.
|
|
15
|
+
* If this function returns true, watchers will be notified of changes. If it returns false, watchers will not be notified.
|
|
16
|
+
* By default equality is defined as deep equality.
|
|
17
|
+
*
|
|
18
|
+
* @param next - The new value being set.
|
|
19
|
+
* @param previous - The previous value being replaced.
|
|
20
|
+
*/
|
|
21
|
+
equality?: (next: T, previous: T) => boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface SignalWatchOptions<T> {
|
|
24
|
+
/**
|
|
25
|
+
* If true the watch callback will be called for the first time on the next change.
|
|
26
|
+
* By default the callback is called immediately with the signal's current value.
|
|
27
|
+
*/
|
|
28
|
+
lazy?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface Signal<T> {
|
|
31
|
+
/**
|
|
32
|
+
* Returns the current value.
|
|
33
|
+
*/
|
|
34
|
+
get(): T;
|
|
35
|
+
/**
|
|
36
|
+
* Watch this signal's value with a `callback` function.
|
|
37
|
+
* The `callback` is only called if the value is not equal to the previous value.
|
|
38
|
+
*
|
|
39
|
+
* > NOTE: If watching a signal inside a view, use the `.watch` method on the `ViewContext`. That method will automatically
|
|
40
|
+
* clean up all watchers when the view is disconnected. Watchers created here must be cleaned up manually.
|
|
41
|
+
*/
|
|
42
|
+
watch(callback: (value: T) => void, options?: SignalWatchOptions<T>): StopFunction;
|
|
43
|
+
}
|
|
44
|
+
export interface SignalSetter<I, O = I> {
|
|
45
|
+
/**
|
|
46
|
+
* Updates the signal's value.
|
|
47
|
+
*/
|
|
48
|
+
(value: O): void;
|
|
49
|
+
/**
|
|
50
|
+
* Takes a callback that receives the signal's current value and returns a new one.
|
|
51
|
+
*/
|
|
52
|
+
(callback: (current: I) => O): void;
|
|
53
|
+
}
|
|
54
|
+
export type MaybeSignal<T> = Signal<T> | T;
|
|
55
|
+
/**
|
|
56
|
+
* A signal and setter in one. Useful for passing signals that are intended to be updated by subviews.
|
|
57
|
+
*/
|
|
58
|
+
export interface SettableSignal<I, O = I> extends Signal<I> {
|
|
59
|
+
/**
|
|
60
|
+
* Updates the signal's value.
|
|
61
|
+
*/
|
|
62
|
+
set(next: O): void;
|
|
63
|
+
/**
|
|
64
|
+
* Takes a callback that recieves the signal's current value and returns a new one.
|
|
65
|
+
*/
|
|
66
|
+
set(callback: (previous: I) => O): void;
|
|
67
|
+
}
|
|
68
|
+
export declare function isSignal<T>(value: any): value is Signal<T>;
|
|
69
|
+
export declare function isSettableSignal<T>(value: any): value is Signal<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves a plain value from a variable that may be a signal.
|
|
72
|
+
*/
|
|
73
|
+
export declare function designalify<T>(value: MaybeSignal<T>): T;
|
|
74
|
+
/**
|
|
75
|
+
* Ensures a variable that may be a signal or plain value is a signal.
|
|
76
|
+
*/
|
|
77
|
+
export declare function signalify<T>(value: MaybeSignal<T>): Signal<T>;
|
|
78
|
+
export interface signal {
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new Signal and setter.
|
|
81
|
+
*/
|
|
82
|
+
/**
|
|
83
|
+
* Creates a new Signal and setter.
|
|
84
|
+
*/
|
|
85
|
+
/**
|
|
86
|
+
* Creates a SettableSignal with an initial value.
|
|
87
|
+
*/
|
|
88
|
+
settable<T>(initialValue: T, options?: SignalCreateOptions<T>): SettableSignal<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Creates a SettableSignal.
|
|
91
|
+
*/
|
|
92
|
+
settable<T>(initialValue?: T, options?: SignalCreateOptions<T | undefined>): SettableSignal<T | undefined>;
|
|
93
|
+
/**
|
|
94
|
+
* Combines a Signal and setter into a SettableSignal.
|
|
95
|
+
*/
|
|
96
|
+
toSettable<I, O = I>(signal: Signal<I>, setter: SignalSetter<I, O>): SettableSignal<I>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a SignalSetter with custom logic provided by `callback`.
|
|
99
|
+
*/
|
|
100
|
+
createSetter<I, O = I>(signal: Signal<I>, callback: (next: O, previous: I) => void): SignalSetter<I, O>;
|
|
101
|
+
}
|
|
102
|
+
export declare function signal<T>(initialValue: T, options?: SignalCreateOptions<T>): [Signal<T>, SignalSetter<T>];
|
|
103
|
+
export declare function signal<T>(initialValue?: T, options?: SignalCreateOptions<T | undefined>): [Signal<T | undefined>, SignalSetter<T | undefined>];
|
|
104
|
+
export declare namespace signal {
|
|
105
|
+
var settable: typeof createSettableSignal;
|
|
106
|
+
var toSettable: typeof createSettableSignalFrom;
|
|
107
|
+
var createSetter: typeof createSignalSetter;
|
|
108
|
+
}
|
|
109
|
+
declare function createSettableSignal<T>(initialValue: T, options?: SignalCreateOptions<T>): SettableSignal<T>;
|
|
110
|
+
declare function createSettableSignal<T>(initialValue?: T, options?: SignalCreateOptions<T | undefined>): SettableSignal<T | undefined>;
|
|
111
|
+
declare function createSettableSignalFrom<I, O = I>(signal: Signal<I>, setter: SignalSetter<I, O>): SettableSignal<I, O>;
|
|
112
|
+
declare function createSignalSetter<I, O = I>(signal: Signal<I>, callback: (next: O, previous: I) => void): SignalSetter<I, O>;
|
|
113
|
+
export interface SignalDeriveOptions {
|
|
114
|
+
equality?: (next: unknown, previous: unknown) => boolean;
|
|
115
|
+
}
|
|
116
|
+
export declare function derive<Inputs extends MaybeSignal<any>[], T>(signals: [...Inputs], fn: (...currentValues: SignalValues<Inputs>) => T | Signal<T>, options?: SignalDeriveOptions): Signal<T>;
|
|
117
|
+
export declare function watch<I extends MaybeSignal<any>[]>(signals: [...I], fn: (...currentValues: SignalValues<I>) => void): StopFunction;
|
|
118
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/state.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Signal } from "./signals.js";
|
|
1
2
|
declare const OBSERVE: unique symbol;
|
|
2
3
|
/**
|
|
3
4
|
* Stops the observer that created it when called.
|
|
4
5
|
*/
|
|
5
6
|
export type StopFunction = () => void;
|
|
6
7
|
type ObserveMethod<T> = (callback: (currentValue: T) => void) => StopFunction;
|
|
7
|
-
type Value<T> = T extends Readable<infer V> ? V : T;
|
|
8
|
+
type Value<T> = T extends Readable<infer V> ? V : T extends Signal<infer V> ? V : T;
|
|
8
9
|
/**
|
|
9
10
|
* Extracts value types from an array of Readables.
|
|
10
11
|
*/
|
|
@@ -34,7 +35,7 @@ export interface Writable<T> extends Readable<T> {
|
|
|
34
35
|
*/
|
|
35
36
|
update(callback: (currentValue: T) => T): void;
|
|
36
37
|
}
|
|
37
|
-
export type MaybeReadable<T> = Readable<T> | T;
|
|
38
|
+
export type MaybeReadable<T> = Readable<T> | Signal<T> | T;
|
|
38
39
|
export declare function isReadable<T>(value: any): value is Readable<T>;
|
|
39
40
|
export declare function isWritable<T>(value: any): value is Writable<T>;
|
|
40
41
|
export declare function $$<T>(value: Writable<T>): Writable<T>;
|
package/lib/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "./app.js";
|
|
2
2
|
import { type DebugChannel } from "./classes/DebugHub.js";
|
|
3
|
-
import { type
|
|
3
|
+
import { type MaybeSignal, type SignalValues, type StopFunction } from "./signals.js";
|
|
4
4
|
import type { BuiltInStores } from "./types.js";
|
|
5
5
|
export type Store<O, E> = (context: StoreContext<O>) => E | Promise<E>;
|
|
6
6
|
export interface StoreContext<Options = any> extends DebugChannel {
|
|
@@ -28,24 +28,7 @@ export interface StoreContext<Options = any> extends DebugChannel {
|
|
|
28
28
|
* Takes an Error object, unmounts the app and displays its crash page.
|
|
29
29
|
*/
|
|
30
30
|
crash(error: Error): void;
|
|
31
|
-
|
|
32
|
-
* Observes a readable value while this store is connected. Calls `callback` each time the value changes.
|
|
33
|
-
*/
|
|
34
|
-
observe<T>(state: MaybeReadable<T>, callback: (currentValue: T) => void): void;
|
|
35
|
-
/**
|
|
36
|
-
* Observes a set of readable values while this store is connected.
|
|
37
|
-
* Calls `callback` with each value in the same order as `readables` each time any of their values change.
|
|
38
|
-
*/
|
|
39
|
-
observe<T extends MaybeReadable<any>[]>(states: [...T], callback: (...currentValues: ReadableValues<T>) => void): void;
|
|
40
|
-
observe<I1, I2>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, callback: (value1: I1, value2: I2) => void): void;
|
|
41
|
-
observe<I1, I2, I3>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, callback: (value1: I1, value2: I2, value3: I3) => void): void;
|
|
42
|
-
observe<I1, I2, I3, I4>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, callback: (value1: I1, value2: I2, value3: I3, value4: I4) => void): void;
|
|
43
|
-
observe<I1, I2, I3, I4, I5>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, callback: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5) => void): void;
|
|
44
|
-
observe<I1, I2, I3, I4, I5, I6>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, callback: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6) => void): void;
|
|
45
|
-
observe<I1, I2, I3, I4, I5, I6, I7>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, state7: MaybeReadable<I7>, callback: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7) => void): void;
|
|
46
|
-
observe<I1, I2, I3, I4, I5, I6, I7, I8>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, state7: MaybeReadable<I7>, state8: MaybeReadable<I8>, callback: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7, value8: I8) => void): void;
|
|
47
|
-
observe<I1, I2, I3, I4, I5, I6, I7, I8, I9>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, state7: MaybeReadable<I7>, state8: MaybeReadable<I8>, state9: MaybeReadable<I9>, callback: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7, value8: I8, value9: I9) => void): void;
|
|
48
|
-
observe<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, state7: MaybeReadable<I7>, state8: MaybeReadable<I8>, state9: MaybeReadable<I9>, state10: MaybeReadable<I10>, callback: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7, value8: I8, value9: I9, value10: I10) => void): void;
|
|
31
|
+
watch<T extends MaybeSignal<any>[]>(signals: [...T], callback: (...values: SignalValues<T>) => void): StopFunction;
|
|
49
32
|
/**
|
|
50
33
|
* Options this store was initialized with.
|
|
51
34
|
*/
|
package/lib/stores/dialog.d.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { type DOMHandle } from "../markup.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type SettableSignal } from "../signals.js";
|
|
3
3
|
import { type StoreContext } from "../store.js";
|
|
4
4
|
import { type View } from "../view.js";
|
|
5
5
|
export interface DialogProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
dialog: {
|
|
7
|
+
/**
|
|
8
|
+
* Whether the dialog is currently open.
|
|
9
|
+
*/
|
|
10
|
+
$$open: SettableSignal<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Calls `callback` immediately after dialog has been connected.
|
|
13
|
+
*/
|
|
14
|
+
transitionIn: (callback: () => Promise<void>) => void;
|
|
15
|
+
/**
|
|
16
|
+
* Calls `callback` and awaits its Promise before disconnecting the dialog.
|
|
17
|
+
*/
|
|
18
|
+
transitionOut: (callback: () => Promise<void>) => void;
|
|
19
|
+
};
|
|
18
20
|
}
|
|
19
21
|
export interface OpenDialog {
|
|
20
22
|
instance: DOMHandle;
|
|
@@ -26,5 +28,5 @@ export interface OpenDialog {
|
|
|
26
28
|
* TODO: Describe this better.
|
|
27
29
|
*/
|
|
28
30
|
export declare function DialogStore(ctx: StoreContext): {
|
|
29
|
-
open: <P extends DialogProps>(view: View<P>, props?: Omit<P,
|
|
31
|
+
open: <P extends DialogProps>(view: View<P>, props?: Omit<P, "dialog"> | undefined) => () => void;
|
|
30
32
|
};
|
package/lib/stores/document.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { type StoreContext } from "../store.js";
|
|
|
2
2
|
type ScreenOrientation = "landscape" | "portrait";
|
|
3
3
|
type ColorScheme = "light" | "dark";
|
|
4
4
|
export declare function DocumentStore(ctx: StoreContext): {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
$
|
|
8
|
-
$
|
|
5
|
+
$title: import("../signals.js").Signal<string>;
|
|
6
|
+
setTitle: import("../signals.js").SignalSetter<string, string>;
|
|
7
|
+
$visibility: import("../signals.js").Signal<DocumentVisibilityState>;
|
|
8
|
+
$orientation: import("../signals.js").Signal<ScreenOrientation>;
|
|
9
|
+
$colorScheme: import("../signals.js").Signal<ColorScheme>;
|
|
9
10
|
};
|
|
10
11
|
export {};
|
package/lib/stores/language.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Signal } from "../signals.js";
|
|
2
2
|
import { type StoreContext } from "../store.js";
|
|
3
3
|
import { type Stringable } from "../types.js";
|
|
4
4
|
/**
|
|
@@ -21,8 +21,8 @@ type LanguageOptions = {
|
|
|
21
21
|
};
|
|
22
22
|
export declare function LanguageStore(ctx: StoreContext<LanguageOptions>): {
|
|
23
23
|
loaded: Promise<void>;
|
|
24
|
-
$isLoaded:
|
|
25
|
-
$currentLanguage:
|
|
24
|
+
$isLoaded: Signal<boolean>;
|
|
25
|
+
$currentLanguage: Signal<string | undefined>;
|
|
26
26
|
supportedLanguages: string[];
|
|
27
27
|
setLanguage: (tag: string) => Promise<void>;
|
|
28
28
|
/**
|
|
@@ -31,6 +31,6 @@ export declare function LanguageStore(ctx: StoreContext<LanguageOptions>): {
|
|
|
31
31
|
* @param key - Key to the translated value.
|
|
32
32
|
* @param values - A map of {{placeholder}} names and the values to replace them with.
|
|
33
33
|
*/
|
|
34
|
-
translate(key: string, values?: Record<string, Stringable |
|
|
34
|
+
translate(key: string, values?: Record<string, Stringable | Signal<Stringable>>): Signal<string>;
|
|
35
35
|
};
|
|
36
36
|
export {};
|
package/lib/stores/router.d.ts
CHANGED
|
@@ -106,19 +106,20 @@ export declare function RouterStore(ctx: StoreContext<RouterStoreOptions>): {
|
|
|
106
106
|
/**
|
|
107
107
|
* The currently matched route pattern, if any.
|
|
108
108
|
*/
|
|
109
|
-
$pattern: import("../
|
|
109
|
+
$pattern: import("../signals.js").Signal<string | null>;
|
|
110
110
|
/**
|
|
111
111
|
* The current URL path.
|
|
112
112
|
*/
|
|
113
|
-
$path: import("../
|
|
113
|
+
$path: import("../signals.js").Signal<string>;
|
|
114
114
|
/**
|
|
115
115
|
* The current named path params.
|
|
116
116
|
*/
|
|
117
|
-
$params: import("../
|
|
117
|
+
$params: import("../signals.js").Signal<ParsedParams>;
|
|
118
118
|
/**
|
|
119
119
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
120
120
|
*/
|
|
121
|
-
|
|
121
|
+
$query: import("../signals.js").Signal<ParsedQuery>;
|
|
122
|
+
setQuery: import("../signals.js").SignalSetter<ParsedQuery, ParsedQuery>;
|
|
122
123
|
/**
|
|
123
124
|
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
124
125
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/types.d.ts
CHANGED
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
import type * as CSS from "csstype";
|
|
2
|
-
import { type Markup } from "./markup.js";
|
|
3
|
-
import { type Readable, type Writable } from "./state.js";
|
|
2
|
+
import { Ref, type Markup } from "./markup.js";
|
|
4
3
|
import { type Store } from "./store.js";
|
|
5
4
|
import { type DocumentStore } from "./stores/document.js";
|
|
6
5
|
import { type RenderStore } from "./stores/render.js";
|
|
7
|
-
|
|
8
|
-
* Value will be read by the component.
|
|
9
|
-
*/
|
|
10
|
-
export type Read<T> = T | Readable<T> | Writable<T>;
|
|
11
|
-
/**
|
|
12
|
-
* Value will be both read and written by the component.
|
|
13
|
-
*/
|
|
14
|
-
export type Write<T> = Writable<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Extracts the value from a Read or Write type.
|
|
17
|
-
*/
|
|
18
|
-
export type Value<T> = T extends Read<infer U> ? U : T;
|
|
6
|
+
import { SettableSignal, Signal } from "./signals.js";
|
|
19
7
|
/**
|
|
20
8
|
* Represents everything that can be handled as a DOM node.
|
|
21
9
|
* These are all the items considered valid to pass as children to any element.
|
|
22
10
|
*/
|
|
23
|
-
export type Renderable = string | number | Markup | false | null | undefined |
|
|
11
|
+
export type Renderable = string | number | Markup | false | null | undefined | Signal<any> | (string | number | Markup | false | null | undefined | Signal<any>)[];
|
|
24
12
|
export type StoreExports<T> = T extends Store<any, infer O> ? O : unknown;
|
|
25
13
|
export interface BuiltInStores {
|
|
26
14
|
document: StoreExports<typeof DocumentStore>;
|
|
@@ -29,9 +17,9 @@ export interface BuiltInStores {
|
|
|
29
17
|
export type Stringable = {
|
|
30
18
|
toString(): string;
|
|
31
19
|
};
|
|
32
|
-
|
|
33
|
-
type OptionalProperty<T> = T |
|
|
34
|
-
type RequiredProperty<T> = T |
|
|
20
|
+
type MaybeSignal<T> = T | Signal<T> | Signal<T | undefined>;
|
|
21
|
+
type OptionalProperty<T> = T | Signal<T> | Signal<T | undefined>;
|
|
22
|
+
type RequiredProperty<T> = T | Signal<T>;
|
|
35
23
|
type AutocapitalizeValues = "off" | "on" | "none" | "sentences" | "words" | "characters";
|
|
36
24
|
type ContentEditableValues = true | false | "true" | "false" | "plaintext-only" | "inherit";
|
|
37
25
|
type ClassListValues = string | ClassMap | Array<string | ClassMap | (string | ClassMap)[]>;
|
|
@@ -130,7 +118,7 @@ export interface ElementProps {
|
|
|
130
118
|
*
|
|
131
119
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/style
|
|
132
120
|
*/
|
|
133
|
-
style?: string | CSSProperties |
|
|
121
|
+
style?: string | CSSProperties | Signal<string> | Signal<CSSProperties> | Signal<string | CSSProperties> | Signal<string | undefined> | Signal<CSSProperties | undefined> | Signal<string | CSSProperties | undefined>;
|
|
134
122
|
/**
|
|
135
123
|
* Fired when a CSS animation unexpectedly aborts.
|
|
136
124
|
*
|
|
@@ -749,6 +737,7 @@ export interface HTMLElementProps extends ElementProps {
|
|
|
749
737
|
/**
|
|
750
738
|
* TODO: Add support. Currently experimental.
|
|
751
739
|
*/
|
|
740
|
+
role?: OptionalProperty<string>;
|
|
752
741
|
/**
|
|
753
742
|
* This element's position in the tab order, or the order this element will be focused as the user cycles through elements with the tab key.
|
|
754
743
|
*
|
|
@@ -1229,7 +1218,7 @@ export type CSSProperties = {
|
|
|
1229
1218
|
[K in keyof Styles]: OptionalProperty<Styles[K]>;
|
|
1230
1219
|
};
|
|
1231
1220
|
export interface ClassMap {
|
|
1232
|
-
[className: string]:
|
|
1221
|
+
[className: string]: MaybeSignal<any>;
|
|
1233
1222
|
}
|
|
1234
1223
|
export type EventHandler<E> = (event: E) => void;
|
|
1235
1224
|
export interface PropertiesOf<E extends HTMLElement> extends HTMLElementProps {
|
|
@@ -1238,9 +1227,9 @@ export interface PropertiesOf<E extends HTMLElement> extends HTMLElementProps {
|
|
|
1238
1227
|
*/
|
|
1239
1228
|
children?: any;
|
|
1240
1229
|
/**
|
|
1241
|
-
* A
|
|
1230
|
+
* A settable signal or callback that receives the DOM node when rendered.
|
|
1242
1231
|
*/
|
|
1243
|
-
ref?:
|
|
1232
|
+
ref?: Ref<E> | Ref<HTMLElement> | Ref<Element> | Ref<Node>;
|
|
1244
1233
|
}
|
|
1245
1234
|
/**
|
|
1246
1235
|
* The following elements are defined based on the WHATWG HTML spec:
|
|
@@ -2117,7 +2106,7 @@ interface HTMLMediaElementProps<T extends HTMLMediaElement> extends HTMLElementP
|
|
|
2117
2106
|
*
|
|
2118
2107
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
|
|
2119
2108
|
*/
|
|
2120
|
-
srcObject?: MediaStream | MediaSource | Blob | File |
|
|
2109
|
+
srcObject?: MediaStream | MediaSource | Blob | File | Signal<MediaStream> | Signal<MediaStream | undefined> | Signal<MediaSource> | Signal<MediaSource | undefined> | Signal<Blob> | Signal<Blob | undefined> | Signal<File> | Signal<File | undefined>;
|
|
2121
2110
|
/**
|
|
2122
2111
|
* The current audio volume of the media element. Must be a number between 0 and 1.
|
|
2123
2112
|
*
|
|
@@ -2616,7 +2605,7 @@ interface HTMLImageElementProps extends PropertiesOf<HTMLImageElement> {
|
|
|
2616
2605
|
*
|
|
2617
2606
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/sizes
|
|
2618
2607
|
*/
|
|
2619
|
-
sizes?:
|
|
2608
|
+
sizes?: MaybeSignal<string>;
|
|
2620
2609
|
/**
|
|
2621
2610
|
* The image URL.
|
|
2622
2611
|
*
|
|
@@ -3157,16 +3146,12 @@ interface HTMLInputElementProps extends PropertiesOf<HTMLInputElement> {
|
|
|
3157
3146
|
popoverTargetAction?: OptionalProperty<"toggle" | "show" | "hide">;
|
|
3158
3147
|
readOnly?: OptionalProperty<boolean>;
|
|
3159
3148
|
required?: OptionalProperty<boolean>;
|
|
3160
|
-
size?: OptionalProperty<number>;
|
|
3149
|
+
size?: OptionalProperty<number | string>;
|
|
3161
3150
|
src?: OptionalProperty<string>;
|
|
3162
3151
|
step?: OptionalProperty<number>;
|
|
3163
3152
|
type?: OptionalProperty<InputType>;
|
|
3164
3153
|
value?: OptionalProperty<string>;
|
|
3165
|
-
|
|
3166
|
-
* Takes a Writable and sets up two-way binding with it.
|
|
3167
|
-
* Any time the user changes the value of this input, that value will be written back to the Writable.
|
|
3168
|
-
*/
|
|
3169
|
-
$$value?: Writable<string>;
|
|
3154
|
+
$$value?: SettableSignal<any>;
|
|
3170
3155
|
width?: OptionalProperty<string | number> | OptionalProperty<string> | OptionalProperty<number>;
|
|
3171
3156
|
title?: OptionalProperty<string>;
|
|
3172
3157
|
/**
|
|
@@ -3218,7 +3203,7 @@ interface HTMLSelectElementProps extends PropertiesOf<HTMLSelectElement> {
|
|
|
3218
3203
|
multiple?: OptionalProperty<boolean>;
|
|
3219
3204
|
name?: OptionalProperty<string>;
|
|
3220
3205
|
required?: OptionalProperty<boolean>;
|
|
3221
|
-
size?: OptionalProperty<number>;
|
|
3206
|
+
size?: OptionalProperty<number | string>;
|
|
3222
3207
|
value?: OptionalProperty<string>;
|
|
3223
3208
|
}
|
|
3224
3209
|
interface HTMLOptGroupElementProps extends PropertiesOf<HTMLOptGroupElement> {
|
|
@@ -3246,7 +3231,6 @@ interface HTMLTextAreaElementProps extends PropertiesOf<HTMLTextAreaElement> {
|
|
|
3246
3231
|
rows?: OptionalProperty<number>;
|
|
3247
3232
|
wrap?: OptionalProperty<"soft" | "hard">;
|
|
3248
3233
|
value?: OptionalProperty<string>;
|
|
3249
|
-
$$value?: Writable<string>;
|
|
3250
3234
|
}
|
|
3251
3235
|
interface HTMLOutputElementProps extends PropertiesOf<HTMLOutputElement> {
|
|
3252
3236
|
for?: OptionalProperty<string>;
|