@manyducks.co/dolla 0.68.1 → 0.69.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 +133 -107
- package/lib/app.d.ts +13 -73
- package/lib/index.d.ts +7 -9
- package/lib/index.js +889 -1098
- package/lib/index.js.map +4 -4
- package/lib/nodes/observer.d.ts +1 -1
- package/lib/nodes/outlet.d.ts +1 -1
- package/lib/nodes/repeat.d.ts +1 -1
- package/lib/spring.d.ts +0 -40
- package/lib/state.d.ts +54 -36
- package/lib/store.d.ts +12 -3
- package/lib/stores/language.d.ts +5 -9
- package/lib/stores/router.d.ts +17 -16
- package/lib/types.d.ts +4 -12
- package/lib/view.d.ts +12 -3
- package/notes/state.md +71 -0
- package/notes/views.md +28 -0
- package/package.json +1 -1
package/lib/nodes/observer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
|
-
import type { Renderable } from "../types.js";
|
|
3
2
|
import { type DOMHandle } from "../markup.js";
|
|
4
3
|
import { type Readable } from "../state.js";
|
|
4
|
+
import type { Renderable } from "../types.js";
|
|
5
5
|
interface ObserverOptions {
|
|
6
6
|
appContext: AppContext;
|
|
7
7
|
elementContext: ElementContext;
|
package/lib/nodes/outlet.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle } from "../markup.js";
|
|
3
3
|
import { type Readable, type StopFunction } from "../state.js";
|
|
4
4
|
export interface OutletConfig {
|
package/lib/nodes/repeat.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "../app.js";
|
|
2
2
|
import { type DOMHandle } from "../markup.js";
|
|
3
|
-
import { type Readable, type
|
|
3
|
+
import { type Readable, type Writable, type StopFunction } from "../state.js";
|
|
4
4
|
import { type ViewContext, type ViewResult } from "../view.js";
|
|
5
5
|
interface RepeatOptions<T> {
|
|
6
6
|
appContext: AppContext;
|
package/lib/spring.d.ts
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type Readable, type Writable } from "./state.js";
|
|
2
|
-
export interface SpringParameters {
|
|
3
|
-
/**
|
|
4
|
-
* How heavy the spring is.
|
|
5
|
-
*/
|
|
6
|
-
mass: number | Readable<number>;
|
|
7
|
-
/**
|
|
8
|
-
* Amount of stiffness or tension in the spring.
|
|
9
|
-
*/
|
|
10
|
-
stiffness: number | Readable<number>;
|
|
11
|
-
/**
|
|
12
|
-
* Amount of smoothing. Affects the speed of transitions.
|
|
13
|
-
*/
|
|
14
|
-
damping: number | Readable<number>;
|
|
15
|
-
/**
|
|
16
|
-
* How much force the spring's motion begins with.
|
|
17
|
-
*/
|
|
18
|
-
velocity: number | Readable<number>;
|
|
19
|
-
}
|
|
20
|
-
interface SpringOptions extends Partial<SpringParameters> {
|
|
21
|
-
/**
|
|
22
|
-
* Difference in average amplitude across the last several frames before the animation is considered done.
|
|
23
|
-
* The exact number of frames to average is specified by `endWindow`.
|
|
24
|
-
*/
|
|
25
|
-
endAmplitude?: number | Readable<number>;
|
|
26
|
-
/**
|
|
27
|
-
* Specifies the number of frames across which to measure the average amplitude to determine when the animation is considered done.
|
|
28
|
-
* The maximum amplitude is specified by `endAmplitude`.
|
|
29
|
-
*/
|
|
30
|
-
endWindow?: number | Readable<number>;
|
|
31
|
-
}
|
|
32
|
-
export interface Spring extends Writable<number> {
|
|
33
|
-
/**
|
|
34
|
-
* Takes a new value and animates to it. Returns a promise that resolves when the animation ends.
|
|
35
|
-
* Optionally takes a set of override spring options to animate with.
|
|
36
|
-
*/
|
|
37
|
-
animateTo(newValue: number, options?: SpringOptions): Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
export declare function spring(initialValue: number, options?: SpringOptions): Spring;
|
|
40
|
-
export {};
|
package/lib/state.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
declare const OBSERVE: unique symbol;
|
|
2
2
|
/**
|
|
3
3
|
* Stops the observer that created it when called.
|
|
4
4
|
*/
|
|
5
5
|
export type StopFunction = () => void;
|
|
6
|
-
type ObserveMethod<T> = (callback: (currentValue: T
|
|
6
|
+
type ObserveMethod<T> = (callback: (currentValue: T) => void) => StopFunction;
|
|
7
7
|
/**
|
|
8
8
|
* Extracts value types from an array of Readables.
|
|
9
9
|
*/
|
|
10
10
|
export type ReadableValues<T extends Readable<any>[]> = {
|
|
11
11
|
[K in keyof T]: T[K] extends Readable<infer U> ? U : never;
|
|
12
12
|
};
|
|
13
|
-
export type Unwrapped<T> = T extends Readable<infer U> ? U : T;
|
|
14
13
|
export interface Observable<T> {
|
|
15
14
|
/**
|
|
16
15
|
* Receives the latest value with `callback` whenever the value changes.
|
|
@@ -34,51 +33,70 @@ export interface Writable<T> extends Readable<T> {
|
|
|
34
33
|
*/
|
|
35
34
|
update(callback: (currentValue: T) => T): void;
|
|
36
35
|
}
|
|
37
|
-
export
|
|
36
|
+
export type MaybeReadable<T> = Readable<T> | T;
|
|
37
|
+
type Value<T> = T extends Readable<infer V> ? V : T;
|
|
38
38
|
export declare function isReadable<T>(value: any): value is Readable<T>;
|
|
39
39
|
export declare function isWritable<T>(value: any): value is Writable<T>;
|
|
40
|
-
export declare function
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function
|
|
43
|
-
export declare function
|
|
44
|
-
export declare function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
40
|
+
export declare function $$<T>(value: Writable<T>): Writable<T>;
|
|
41
|
+
export declare function $$<T>(value: Readable<T>): never;
|
|
42
|
+
export declare function $$<T>(value: undefined): Writable<T | undefined>;
|
|
43
|
+
export declare function $$<T>(): Writable<T | undefined>;
|
|
44
|
+
export declare function $$<T>(value: T): Writable<Value<T>>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a proxy `Writable` around an existing `Writable`.
|
|
47
|
+
* The config object contains custom `get` and `set` methods.
|
|
48
|
+
* All reads of this proxy goes through the `get` method
|
|
49
|
+
* and all writes go through `set`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function $$<Source extends Writable<any>, Value>(source: Source, config: ProxyConfig<Value>): Writable<Value>;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a proxy `Writable` around an existing `Readable`.
|
|
54
|
+
* The config object contains custom `get` and `set` methods.
|
|
55
|
+
* All reads of this proxy goes through the `get` method
|
|
56
|
+
* and all writes go through `set`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function $$<Source extends Readable<any>, Value>(source: Source, config: ProxyConfig<Value>): Writable<Value>;
|
|
59
|
+
export declare function $<T>(value: Writable<T>): Readable<T>;
|
|
60
|
+
export declare function $<T>(value: Readable<T>): Readable<T>;
|
|
61
|
+
export declare function $<T>(value: undefined): Readable<T | undefined>;
|
|
62
|
+
export declare function $<T>(): Readable<T | undefined>;
|
|
63
|
+
export declare function $<T>(value: T): Readable<Value<T>>;
|
|
64
|
+
export declare function $<I, O>(state: MaybeReadable<I>, compute: (value: I) => O | Readable<O>): Readable<O>;
|
|
65
|
+
export declare function $<I extends MaybeReadable<any>[], O>(states: [...I], compute: (...currentValues: ReadableValues<I>) => O | Readable<O>): Readable<O>;
|
|
66
|
+
export declare function $<I1, I2, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, compute: (value1: I1, value2: I2) => O | Readable<O>): Readable<O>;
|
|
67
|
+
export declare function $<I1, I2, I3, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, compute: (value1: I1, value2: I2, value3: I3) => O | Readable<O>): Readable<O>;
|
|
68
|
+
export declare function $<I1, I2, I3, I4, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, compute: (value1: I1, value2: I2, value3: I3, value4: I4) => O | Readable<O>): Readable<O>;
|
|
69
|
+
export declare function $<I1, I2, I3, I4, I5, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, compute: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5) => O | Readable<O>): Readable<O>;
|
|
70
|
+
export declare function $<I1, I2, I3, I4, I5, I6, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, compute: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6) => O | Readable<O>): Readable<O>;
|
|
71
|
+
export declare function $<I1, I2, I3, I4, I5, I6, I7, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, state7: MaybeReadable<I7>, compute: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7) => O | Readable<O>): Readable<O>;
|
|
72
|
+
export declare function $<I1, I2, I3, I4, I5, I6, I7, I8, O>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, state4: MaybeReadable<I4>, state5: MaybeReadable<I5>, state6: MaybeReadable<I6>, state7: MaybeReadable<I7>, state8: MaybeReadable<I8>, compute: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7, value8: I8) => O | Readable<O>): Readable<O>;
|
|
73
|
+
export declare function $<I1, I2, I3, I4, I5, I6, I7, I8, I9, O>(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>, compute: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7, value8: I8, value9: I9) => O | Readable<O>): Readable<O>;
|
|
74
|
+
export declare function $<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, O>(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>, compute: (value1: I1, value2: I2, value3: I3, value4: I4, value5: I5, value6: I6, value7: I7, value8: I8, value9: I9, value10: I10) => O | Readable<O>): Readable<O>;
|
|
75
|
+
interface ProxyConfig<Value> {
|
|
76
|
+
get(): Value;
|
|
77
|
+
set(value: Value): void;
|
|
78
|
+
}
|
|
50
79
|
/**
|
|
51
80
|
* Observes a readable value. Calls `callback` each time the value changes.
|
|
52
81
|
* Returns a function to stop observing changes. This MUST be called when you are done
|
|
53
82
|
* with this observer to prevent memory leaks.
|
|
54
83
|
*/
|
|
55
|
-
export declare function observe<T>(
|
|
84
|
+
export declare function observe<T>(state: Readable<T>, callback: (currentValue: T, previousValue: T) => void): StopFunction;
|
|
56
85
|
/**
|
|
57
86
|
* Observes a set of readable values.
|
|
58
87
|
* Calls `callback` with each value in the same order as `readables` each time any of their values change.
|
|
59
88
|
* Returns a function to stop observing changes. This MUST be called when you are done
|
|
60
89
|
* with this observer to prevent memory leaks.
|
|
61
90
|
*/
|
|
62
|
-
export declare function observe<T extends
|
|
63
|
-
export declare function
|
|
64
|
-
export declare function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* All reads of this proxy goes through the `get` method
|
|
73
|
-
* and all writes go through `set`.
|
|
74
|
-
*/
|
|
75
|
-
export declare function proxy<Source extends Writable<any>, Value>(source: Source, config: ProxyConfig<Source, Value>): Writable<Value>;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a proxy `Writable` around an existing `Readable`.
|
|
78
|
-
* The config object takes custom `get` and `set` methods.
|
|
79
|
-
* All reads of this proxy goes through the `get` method
|
|
80
|
-
* and all writes go through `set`.
|
|
81
|
-
*/
|
|
82
|
-
export declare function proxy<Source extends Readable<any>, Value>(source: Source, config: ProxyConfig<Source, Value>): Writable<Value>;
|
|
91
|
+
export declare function observe<T extends MaybeReadable<any>[]>(states: [...T], callback: (currentValues: ReadableValues<T>, previousValues: ReadableValues<T>) => void): StopFunction;
|
|
92
|
+
export declare function observe<I1, I2>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, callback: (value1: I1, value2: I2) => void): StopFunction;
|
|
93
|
+
export declare function observe<I1, I2, I3>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, callback: (value1: I1, value2: I2, value3: I3) => void): StopFunction;
|
|
94
|
+
export declare function 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): StopFunction;
|
|
95
|
+
export declare function 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): StopFunction;
|
|
96
|
+
export declare function 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): StopFunction;
|
|
97
|
+
export declare function 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): StopFunction;
|
|
98
|
+
export declare function 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): StopFunction;
|
|
99
|
+
export declare function 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): StopFunction;
|
|
100
|
+
export declare function 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): StopFunction;
|
|
83
101
|
export declare function unwrap<T>(value: Readable<T> | T): T;
|
|
84
102
|
export {};
|
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 {
|
|
3
|
+
import { MaybeReadable, type ReadableValues } from "./state.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 {
|
|
@@ -31,12 +31,21 @@ export interface StoreContext<Options = any> extends DebugChannel {
|
|
|
31
31
|
/**
|
|
32
32
|
* Observes a readable value while this store is connected. Calls `callback` each time the value changes.
|
|
33
33
|
*/
|
|
34
|
-
observe<T>(
|
|
34
|
+
observe<T>(state: MaybeReadable<T>, callback: (currentValue: T) => void): void;
|
|
35
35
|
/**
|
|
36
36
|
* Observes a set of readable values while this store is connected.
|
|
37
37
|
* Calls `callback` with each value in the same order as `readables` each time any of their values change.
|
|
38
38
|
*/
|
|
39
|
-
observe<T extends
|
|
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;
|
|
40
49
|
/**
|
|
41
50
|
* Options this store was initialized with.
|
|
42
51
|
*/
|
package/lib/stores/language.d.ts
CHANGED
|
@@ -6,22 +6,18 @@ import { type Stringable } from "../types.js";
|
|
|
6
6
|
*/
|
|
7
7
|
type Translation = Record<string, string | Record<string, string | Record<string, string | Record<string, string>>>>;
|
|
8
8
|
export interface LanguageConfig {
|
|
9
|
+
name: string;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Path to a JSON file with translated strings for this language, a plain object containing said translations, or a callback function that returns them.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
+
translations: string | Translation | (() => Translation) | (() => Promise<Translation>);
|
|
13
14
|
}
|
|
14
15
|
type LanguageOptions = {
|
|
15
|
-
|
|
16
|
-
* Languages supported by the app (as added with App.language())
|
|
17
|
-
*/
|
|
18
|
-
languages: {
|
|
19
|
-
[tag: string]: LanguageConfig;
|
|
20
|
-
};
|
|
16
|
+
languages: LanguageConfig[];
|
|
21
17
|
/**
|
|
22
18
|
* Default language to load on startup
|
|
23
19
|
*/
|
|
24
|
-
|
|
20
|
+
default?: string;
|
|
25
21
|
};
|
|
26
22
|
export declare function LanguageStore(ctx: StoreContext<LanguageOptions>): {
|
|
27
23
|
$isLoaded: Readable<boolean>;
|
package/lib/stores/router.d.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { type Route } from "@borf/bedrock";
|
|
2
1
|
import { type History } from "history";
|
|
3
|
-
import { type Stringable } from "../types.js";
|
|
4
2
|
import { type Markup } from "../markup.js";
|
|
5
3
|
import { type StoreContext } from "../store.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
* @see https://www.npmjs.com/package/history
|
|
15
|
-
*/
|
|
16
|
-
history?: History;
|
|
4
|
+
import { type Stringable } from "../types.js";
|
|
5
|
+
import { View } from "../view.js";
|
|
6
|
+
export interface Route {
|
|
7
|
+
path: string;
|
|
8
|
+
redirect?: string;
|
|
9
|
+
view?: View<any>;
|
|
10
|
+
routes?: Route[];
|
|
17
11
|
}
|
|
18
12
|
export interface RouteConfig {
|
|
19
13
|
pattern: string;
|
|
@@ -60,11 +54,18 @@ interface NavigateOptions {
|
|
|
60
54
|
*/
|
|
61
55
|
replace?: boolean;
|
|
62
56
|
}
|
|
63
|
-
interface RouterStoreOptions
|
|
57
|
+
interface RouterStoreOptions {
|
|
58
|
+
routes: Route[];
|
|
59
|
+
/**
|
|
60
|
+
* Use hash-based routing if true.
|
|
61
|
+
*/
|
|
62
|
+
hash?: boolean;
|
|
64
63
|
/**
|
|
65
|
-
*
|
|
64
|
+
* A history object from the `history` package.
|
|
65
|
+
*
|
|
66
|
+
* @see https://www.npmjs.com/package/history
|
|
66
67
|
*/
|
|
67
|
-
|
|
68
|
+
history?: History;
|
|
68
69
|
}
|
|
69
70
|
export declare function RouterStore(ctx: StoreContext<RouterStoreOptions>): {
|
|
70
71
|
/**
|
package/lib/types.d.ts
CHANGED
|
@@ -2,12 +2,8 @@ import type * as CSS from "csstype";
|
|
|
2
2
|
import { type Markup } from "./markup.js";
|
|
3
3
|
import { type Readable, type Writable } from "./state.js";
|
|
4
4
|
import { type Store } from "./store.js";
|
|
5
|
-
import { type DialogStore } from "./stores/dialog.js";
|
|
6
5
|
import { type DocumentStore } from "./stores/document.js";
|
|
7
|
-
import { type HTTPStore } from "./stores/http.js";
|
|
8
|
-
import { type LanguageStore } from "./stores/language.js";
|
|
9
6
|
import { RenderStore } from "./stores/render.js";
|
|
10
|
-
import { type RouterStore } from "./stores/router.js";
|
|
11
7
|
/**
|
|
12
8
|
* Value will be read by the component.
|
|
13
9
|
*/
|
|
@@ -27,11 +23,7 @@ export type Value<T> = T extends Read<infer U> ? U : T;
|
|
|
27
23
|
export type Renderable = string | number | Markup | false | null | undefined | Readable<any> | (string | number | Markup | false | null | undefined | Readable<any>)[];
|
|
28
24
|
export type StoreExports<T> = T extends Store<any, infer O> ? O : unknown;
|
|
29
25
|
export interface BuiltInStores {
|
|
30
|
-
http: StoreExports<typeof HTTPStore>;
|
|
31
|
-
dialog: StoreExports<typeof DialogStore>;
|
|
32
|
-
language: StoreExports<typeof LanguageStore>;
|
|
33
26
|
document: StoreExports<typeof DocumentStore>;
|
|
34
|
-
router: StoreExports<typeof RouterStore>;
|
|
35
27
|
render: StoreExports<typeof RenderStore>;
|
|
36
28
|
}
|
|
37
29
|
export type Stringable = {
|
|
@@ -1592,14 +1584,14 @@ export interface IntrinsicElements {
|
|
|
1592
1584
|
*/
|
|
1593
1585
|
rp: PropertiesOf<HTMLElement>;
|
|
1594
1586
|
/**
|
|
1595
|
-
* Wraps a piece of content, providing an additional machine-
|
|
1587
|
+
* Wraps a piece of content, providing an additional machine-Readable version in a `value` attribute.
|
|
1596
1588
|
* For date or time related data, a `<time>` element is preferred.
|
|
1597
1589
|
*
|
|
1598
1590
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data
|
|
1599
1591
|
*/
|
|
1600
1592
|
data: HTMLDataElementProps;
|
|
1601
1593
|
/**
|
|
1602
|
-
* Represents a specific period in time. It may include the `datetime` attribute to translate dates into machine-
|
|
1594
|
+
* Represents a specific period in time. It may include the `datetime` attribute to translate dates into machine-Readable format,
|
|
1603
1595
|
* allowing for better search engine results or custom features such as reminders.
|
|
1604
1596
|
*
|
|
1605
1597
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
|
|
@@ -1796,7 +1788,7 @@ interface HTMLAbbrElementProps extends PropertiesOf<HTMLElement> {
|
|
|
1796
1788
|
}
|
|
1797
1789
|
interface HTMLDataElementProps extends PropertiesOf<HTMLDataElement> {
|
|
1798
1790
|
/**
|
|
1799
|
-
* Specifies the machine-
|
|
1791
|
+
* Specifies the machine-Readable translation of the content of the element.
|
|
1800
1792
|
*
|
|
1801
1793
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data
|
|
1802
1794
|
*/
|
|
@@ -2768,7 +2760,7 @@ interface HTMLTrackElementProps extends PropertiesOf<HTMLTrackElement> {
|
|
|
2768
2760
|
*/
|
|
2769
2761
|
kind?: OptionalProperty<"subtitles" | "captions" | "descriptions" | "chapters" | "metadata">;
|
|
2770
2762
|
/**
|
|
2771
|
-
* A user-
|
|
2763
|
+
* A user-Readable title of the text track which is used by the browser when listing available text tracks.
|
|
2772
2764
|
*/
|
|
2773
2765
|
label?: OptionalProperty<string>;
|
|
2774
2766
|
/**
|
package/lib/view.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AppContext, type ElementContext } from "./app.js";
|
|
2
2
|
import { type DebugChannel } from "./classes/DebugHub.js";
|
|
3
3
|
import { type DOMHandle, type Markup } from "./markup.js";
|
|
4
|
-
import { type Readable, type ReadableValues } from "./state.js";
|
|
4
|
+
import { type Readable, type ReadableValues, type MaybeReadable } from "./state.js";
|
|
5
5
|
import { type Store } from "./store.js";
|
|
6
6
|
import type { BuiltInStores } from "./types.js";
|
|
7
7
|
/**
|
|
@@ -49,12 +49,21 @@ export interface ViewContext extends DebugChannel {
|
|
|
49
49
|
/**
|
|
50
50
|
* Observes a readable value while this view is connected. Calls `callback` each time the value changes.
|
|
51
51
|
*/
|
|
52
|
-
observe<T>(
|
|
52
|
+
observe<T>(state: MaybeReadable<T>, callback: (currentValue: T) => void): void;
|
|
53
53
|
/**
|
|
54
54
|
* Observes a set of readable values while this view is connected.
|
|
55
55
|
* Calls `callback` with each value in the same order as `readables` each time any of their values change.
|
|
56
56
|
*/
|
|
57
|
-
observe<T extends
|
|
57
|
+
observe<T extends MaybeReadable<any>[]>(states: [...T], callback: (...currentValues: ReadableValues<T>) => void): void;
|
|
58
|
+
observe<I1, I2>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, callback: (value1: I1, value2: I2) => void): void;
|
|
59
|
+
observe<I1, I2, I3>(state1: MaybeReadable<I1>, state2: MaybeReadable<I2>, state3: MaybeReadable<I3>, callback: (value1: I1, value2: I2, value3: I3) => void): void;
|
|
60
|
+
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;
|
|
61
|
+
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;
|
|
62
|
+
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;
|
|
63
|
+
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;
|
|
64
|
+
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;
|
|
65
|
+
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;
|
|
66
|
+
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;
|
|
58
67
|
/**
|
|
59
68
|
* Returns a Markup element that displays this view's children.
|
|
60
69
|
*/
|
package/notes/state.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# State
|
|
2
|
+
|
|
3
|
+
I want to update the state API to be a single constructor object, similar to built-ins like `Math` and `Array`. The current API has a lot of separate functions that work together in various ways, but I feel it would be easier to explain and understand if these functions were under one namespace.
|
|
4
|
+
|
|
5
|
+
Current API:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { readable, writable, computed, unwrap, proxy, type Readable, type Writable } from "@manyducks.co/dolla";
|
|
9
|
+
|
|
10
|
+
const $$writable = writable({ someValue: 5, otherValue: "test" });
|
|
11
|
+
const $readable = readable($$writable);
|
|
12
|
+
const $computed = computed($$writable, (value) => value.someValue * 256);
|
|
13
|
+
const unwrapped = unwrap($computed);
|
|
14
|
+
const $$proxy = proxy($$writable, {
|
|
15
|
+
get(source) {
|
|
16
|
+
return source.get().someValue;
|
|
17
|
+
},
|
|
18
|
+
set(source, value) {
|
|
19
|
+
source.update((current) => {
|
|
20
|
+
return { ...current, someValue: value };
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
const $multiComputed = computed([$one, $$two, $three], ([one, two, three], [oldOne, oldTwo, oldThree]) => {
|
|
25
|
+
return one + two + three;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
$$writable.get();
|
|
29
|
+
$$writable.set({ someValue: 12, otherValue: null });
|
|
30
|
+
$$writable.update((current) => ({ ...current, someValue: 100 }));
|
|
31
|
+
|
|
32
|
+
$readable.get();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The main problem with the above is that we have two things (readable and writable) and a bunch of disconnected utility functions.
|
|
36
|
+
|
|
37
|
+
Proposed API:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { State, type Readable, type Writable } from "@manyducks.co/dolla";
|
|
41
|
+
|
|
42
|
+
const $$writable = State.writable({ someValue: 5, otherValue: "test" }); // Longhand
|
|
43
|
+
const $$writable = State({ someValue: 5, otherValue: "test" }); // Shorthand
|
|
44
|
+
const $readable = State.readable($$writable);
|
|
45
|
+
const $readable = $$writable.readable(); // Directly from a writable
|
|
46
|
+
const $computed = State.from($$writable, (value) => value.someValue * 256);
|
|
47
|
+
const unwrapped = State.unwrap($computed);
|
|
48
|
+
const $$proxy = State.proxy($$writable, {
|
|
49
|
+
get(current) {
|
|
50
|
+
return current.someValue;
|
|
51
|
+
},
|
|
52
|
+
set(value, update) {
|
|
53
|
+
update((current) => {
|
|
54
|
+
return { ...current, someValue: value };
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
const $multiComputed = State.from($one, $$two, $three, (one, two, three, ctx) => {
|
|
59
|
+
// ctx.lastValues = [oldOne, oldTwo, oldThree];
|
|
60
|
+
// ctx.lastReturned = oldOne + oldTwo + oldThree
|
|
61
|
+
return one + two + three;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
$$writable.get();
|
|
65
|
+
$$writable.set({ someValue: 12, otherValue: null });
|
|
66
|
+
$$writable.update((current) => ({ ...current, someValue: 100 }));
|
|
67
|
+
|
|
68
|
+
$readable.get();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Now we have one state primitive (`State`), all instances of which implement `Readable` and some of which implement `Writable`. All utility functions are under the same namespace. This also avoids conflicts with Node streams' Readable and Writable which can be an issue with automatic imports.
|
package/notes/views.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
```js
|
|
2
|
+
import { View, Store, State } from "@manyducks.co/dolla";
|
|
3
|
+
|
|
4
|
+
const SomeView = View("SomeView")
|
|
5
|
+
.props((t) => ({
|
|
6
|
+
// Define prop types which are validated and enforced in dev mode
|
|
7
|
+
$name: t.readable(t.string().optional()).optional(), // Readable<string | undefined> | undefined
|
|
8
|
+
}))
|
|
9
|
+
.build(({ $name }, ctx) => {
|
|
10
|
+
const { $value } = ctx.getStore(SomeStore);
|
|
11
|
+
|
|
12
|
+
return <h1>Hello {$name}</h1>;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const SomeStore = Store("SomeStore").build((ctx) => {
|
|
16
|
+
const $$value = State(0);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
$value: $$value.readable(),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Stores can be configured in an app like so:
|
|
24
|
+
|
|
25
|
+
const app = App();
|
|
26
|
+
|
|
27
|
+
app.addStore(SomeStore.configure(options));
|
|
28
|
+
```
|