@manyducks.co/dolla 0.67.0
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 +643 -0
- package/build.js +34 -0
- package/index.d.ts +12 -0
- package/jsx-dev-runtime.d.ts +1 -0
- package/jsx-runtime.d.ts +1 -0
- package/lib/app.d.ts +138 -0
- package/lib/classes/CrashCollector.d.ts +30 -0
- package/lib/classes/DebugHub.d.ts +60 -0
- package/lib/index.d.ts +23 -0
- package/lib/index.js +4062 -0
- package/lib/index.js.map +7 -0
- package/lib/jsx/jsx-dev-runtime.d.ts +3 -0
- package/lib/jsx/jsx-dev-runtime.js +20 -0
- package/lib/jsx/jsx-dev-runtime.js.map +7 -0
- package/lib/jsx/jsx-runtime.d.ts +10 -0
- package/lib/jsx/jsx-runtime.js +22 -0
- package/lib/jsx/jsx-runtime.js.map +7 -0
- package/lib/markup.d.ts +81 -0
- package/lib/nodes/cond.d.ts +28 -0
- package/lib/nodes/html.d.ts +30 -0
- package/lib/nodes/observer.d.ts +33 -0
- package/lib/nodes/outlet.d.ts +26 -0
- package/lib/nodes/portal.d.ts +22 -0
- package/lib/nodes/repeat.d.ts +36 -0
- package/lib/nodes/text.d.ts +20 -0
- package/lib/spring.d.ts +40 -0
- package/lib/state.d.ts +84 -0
- package/lib/store.d.ts +67 -0
- package/lib/stores/dialog.d.ts +30 -0
- package/lib/stores/document.d.ts +10 -0
- package/lib/stores/http.d.ts +60 -0
- package/lib/stores/language.d.ts +39 -0
- package/lib/stores/render.d.ts +18 -0
- package/lib/stores/router.d.ts +118 -0
- package/lib/testing/classes/MockHTTP.d.ts +10 -0
- package/lib/testing/index.d.ts +4 -0
- package/lib/testing/makeMockDOMNode.d.ts +10 -0
- package/lib/testing/makeMockFetch.d.ts +36 -0
- package/lib/testing/makeMockFetch.test.d.ts +1 -0
- package/lib/testing/stores/dialog.d.ts +6 -0
- package/lib/testing/stores/http.d.ts +13 -0
- package/lib/testing/stores/page.d.ts +7 -0
- package/lib/testing/stores/router.d.ts +12 -0
- package/lib/testing/wrapStore.d.ts +8 -0
- package/lib/testing/wrapStore.test.d.ts +1 -0
- package/lib/testing/wrapView.d.ts +0 -0
- package/lib/types.d.ts +3388 -0
- package/lib/utils.d.ts +14 -0
- package/lib/view.d.ts +80 -0
- package/lib/views/fragment.d.ts +2 -0
- package/lib/views/store-scope.d.ts +10 -0
- package/package.json +56 -0
- package/tests/state.test.js +290 -0
package/lib/app.d.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { CrashCollector } from "./classes/CrashCollector.js";
|
|
2
|
+
import { DebugHub, type DebugOptions } from "./classes/DebugHub.js";
|
|
3
|
+
import { DOMHandle } from "./markup.js";
|
|
4
|
+
import { initStore, type Store } from "./store.js";
|
|
5
|
+
import { type LanguageConfig } from "./stores/language.js";
|
|
6
|
+
import { type RedirectContext, type RouterOptions } from "./stores/router.js";
|
|
7
|
+
import { type BuiltInStores } from "./types.js";
|
|
8
|
+
import { type View } from "./view.js";
|
|
9
|
+
interface AppOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Options for the debug system.
|
|
12
|
+
*/
|
|
13
|
+
debug?: DebugOptions;
|
|
14
|
+
/**
|
|
15
|
+
* Options to configure how routing works.
|
|
16
|
+
*/
|
|
17
|
+
router?: RouterOptions;
|
|
18
|
+
/**
|
|
19
|
+
* Configures the app based on the environment it's running in.
|
|
20
|
+
*/
|
|
21
|
+
mode?: "development" | "production";
|
|
22
|
+
}
|
|
23
|
+
export interface AppContext {
|
|
24
|
+
crashCollector: CrashCollector;
|
|
25
|
+
debugHub: DebugHub;
|
|
26
|
+
stores: Map<keyof BuiltInStores | StoreRegistration["store"], StoreRegistration>;
|
|
27
|
+
mode: "development" | "production";
|
|
28
|
+
rootElement?: HTMLElement;
|
|
29
|
+
rootView?: DOMHandle;
|
|
30
|
+
}
|
|
31
|
+
export interface ElementContext {
|
|
32
|
+
stores: Map<StoreRegistration["store"], StoreRegistration>;
|
|
33
|
+
isSVG?: boolean;
|
|
34
|
+
componentName?: string;
|
|
35
|
+
parent?: ElementContext;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* An object kept in App for each store registered with `addStore`.
|
|
39
|
+
*/
|
|
40
|
+
export interface StoreRegistration<O = any> {
|
|
41
|
+
store: Store<O, any>;
|
|
42
|
+
options?: O;
|
|
43
|
+
instance?: ReturnType<typeof initStore>;
|
|
44
|
+
}
|
|
45
|
+
interface AppRouter {
|
|
46
|
+
/**
|
|
47
|
+
* Adds a new pattern, a view to display while that pattern matches the current URL, and an optional function to configure route chaining.
|
|
48
|
+
* Route chaining allows you to add nested routes and redirects that are displayed within the `view`'s outlet while `pattern` matches the current URL.
|
|
49
|
+
*
|
|
50
|
+
* @param pattern - A URL pattern to match against the current URL.
|
|
51
|
+
* @param view - The view to display while `pattern` matches the current URL.
|
|
52
|
+
* @param subroutes - A callback that takes a router object. Use this to append nested routes and redirects.
|
|
53
|
+
*/
|
|
54
|
+
route<I>(pattern: string, view: View<I>, subroutes?: (router: AppRouter) => void): this;
|
|
55
|
+
/**
|
|
56
|
+
* Adds a new pattern and chains a set of nested routes that are displayed without a layout `view`.
|
|
57
|
+
*
|
|
58
|
+
* @param pattern - A URL pattern to match against the current URL.
|
|
59
|
+
* @param view - Pass null to render subroutes without a parent view.
|
|
60
|
+
* @param subroutes - A callback that takes a router object. Use this to append nested routes and redirects.
|
|
61
|
+
*/
|
|
62
|
+
route(pattern: string, view: null, subroutes: (router: AppRouter) => void): this;
|
|
63
|
+
/**
|
|
64
|
+
* Adds a new pattern that will redirect to a different route when matched.
|
|
65
|
+
*
|
|
66
|
+
* @param pattern - A URL pattern to match against the current URL.
|
|
67
|
+
* @param redirectPath - A path to redirect to when `pattern` matches the current URL.
|
|
68
|
+
*/
|
|
69
|
+
redirect(pattern: string, redirectPath: string): this;
|
|
70
|
+
/**
|
|
71
|
+
* Adds a new pattern that will redirect to a different route when matched, as calculated by a callback function.
|
|
72
|
+
* Useful when you require more insight into the path that matched the pattern before deciding where to send the user.
|
|
73
|
+
*
|
|
74
|
+
* @param pattern - A URL pattern to match against the current URL.
|
|
75
|
+
* @param createPath - A function that generates a redirect path from the current URL match.
|
|
76
|
+
*/
|
|
77
|
+
redirect(pattern: string, createPath: (ctx: RedirectContext) => string): this;
|
|
78
|
+
}
|
|
79
|
+
interface ConfigureContext {
|
|
80
|
+
}
|
|
81
|
+
type ConfigureCallback = (ctx: ConfigureContext) => void | Promise<void>;
|
|
82
|
+
export interface App extends AppRouter {
|
|
83
|
+
readonly isConnected: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Displays view at the root of the app. All other routes render inside this view's outlet.
|
|
86
|
+
*/
|
|
87
|
+
main<A extends Record<string, any>>(view: View<A>, attributes?: A): this;
|
|
88
|
+
/**
|
|
89
|
+
* Makes this store accessible from any other component in the app, except for stores registered before this one.
|
|
90
|
+
*/
|
|
91
|
+
store<O>(store: Store<O, any>, options?: O): this;
|
|
92
|
+
/**
|
|
93
|
+
* Returns the shared instance of `store`.
|
|
94
|
+
*/
|
|
95
|
+
getStore<T extends Store<any, any>>(store: T): ReturnType<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the shared instance of a built-in store.
|
|
98
|
+
*/
|
|
99
|
+
getStore<N extends keyof BuiltInStores>(name: N): BuiltInStores[N];
|
|
100
|
+
/**
|
|
101
|
+
* Adds a new language translation to the app.
|
|
102
|
+
*
|
|
103
|
+
* @param tag - A valid BCP47 language tag, like `en-US`, `en-GB`, `ja`, etc.
|
|
104
|
+
* @param config - Language configuration.
|
|
105
|
+
*/
|
|
106
|
+
language(tag: string, config: LanguageConfig): this;
|
|
107
|
+
/**
|
|
108
|
+
* Sets the initial language. The app will default to the first language added if this is not called.
|
|
109
|
+
*/
|
|
110
|
+
setLanguage(tag: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Sets the initial language based on the user's locale.
|
|
113
|
+
* Falls back to `fallback` language if provided, otherwise falls back to the first language added.
|
|
114
|
+
*
|
|
115
|
+
* @param tag - Set to "auto" to autodetect the user's language.
|
|
116
|
+
* @param fallback - The language tag to default to if the app fails to detect an appropriate language.
|
|
117
|
+
*/
|
|
118
|
+
setLanguage(tag: "auto", fallback?: string): this;
|
|
119
|
+
/**
|
|
120
|
+
* Runs `callback` after app-level stores are connected to the app, but before views are connected to the DOM.
|
|
121
|
+
* Use this function to run async configuration code before displaying content to the user.
|
|
122
|
+
*
|
|
123
|
+
* Note that this will delay content being displayed on the screen, so using some kind of splash screen is recommended.
|
|
124
|
+
*/
|
|
125
|
+
configure(callback: ConfigureCallback): this;
|
|
126
|
+
/**
|
|
127
|
+
* Initializes and connects the app as a child of `element`.
|
|
128
|
+
*
|
|
129
|
+
* @param element - A selector string or a DOM node to attach to. If a string, follows the same format as that taken by `document.querySelector`.
|
|
130
|
+
*/
|
|
131
|
+
connect(selector: string | Node): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Disconnects views and tears down globals, removing the app from the page.
|
|
134
|
+
*/
|
|
135
|
+
disconnect(): Promise<void>;
|
|
136
|
+
}
|
|
137
|
+
export declare function makeApp(options?: AppOptions): App;
|
|
138
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface ErrorContext {
|
|
2
|
+
error: Error;
|
|
3
|
+
severity: "error" | "crash";
|
|
4
|
+
componentName: string;
|
|
5
|
+
}
|
|
6
|
+
interface CrashOptions {
|
|
7
|
+
error: Error;
|
|
8
|
+
componentName?: string;
|
|
9
|
+
}
|
|
10
|
+
type ErrorCallback = (ctx: ErrorContext) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Receives errors that occur in components.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CrashCollector {
|
|
15
|
+
#private;
|
|
16
|
+
/**
|
|
17
|
+
* Registers a callback to receive all errors that pass through the CrashCollector.
|
|
18
|
+
* Returns a function that cancels this listener when called.
|
|
19
|
+
*/
|
|
20
|
+
onError(callback: ErrorCallback): () => void;
|
|
21
|
+
/**
|
|
22
|
+
* Reports an unrecoverable error that requires crashing the whole app.
|
|
23
|
+
*/
|
|
24
|
+
crash({ error, componentName }: CrashOptions): void;
|
|
25
|
+
/**
|
|
26
|
+
* Reports a recoverable error.
|
|
27
|
+
*/
|
|
28
|
+
error({ error, componentName }: CrashOptions): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type CrashCollector } from "./CrashCollector.js";
|
|
2
|
+
export type DebugOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Determines which debug channels are printed. Supports multiple filters with commas,
|
|
5
|
+
* a prepended `-` to exclude a channel and wildcards to match partial channels.
|
|
6
|
+
*
|
|
7
|
+
* @example "store:*,-store:test" // matches everything starting with "store" except "store:test"
|
|
8
|
+
*/
|
|
9
|
+
filter?: string | RegExp;
|
|
10
|
+
/**
|
|
11
|
+
* Print info messages when true. Default: true for development builds, false for production builds.
|
|
12
|
+
*/
|
|
13
|
+
info?: boolean | "development";
|
|
14
|
+
/**
|
|
15
|
+
* Print log messages when true. Default: true for development builds, false for production builds.
|
|
16
|
+
*/
|
|
17
|
+
log?: boolean | "development";
|
|
18
|
+
/**
|
|
19
|
+
* Print warn messages when true. Default: true for development builds, false for production builds.
|
|
20
|
+
*/
|
|
21
|
+
warn?: boolean | "development";
|
|
22
|
+
/**
|
|
23
|
+
* Print error messages when true. Default: true.
|
|
24
|
+
*/
|
|
25
|
+
error?: boolean | "development";
|
|
26
|
+
};
|
|
27
|
+
type DebugHubOptions = DebugOptions & {
|
|
28
|
+
crashCollector: CrashCollector;
|
|
29
|
+
mode: "development" | "production";
|
|
30
|
+
};
|
|
31
|
+
export interface DebugChannelOptions {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DebugChannel {
|
|
35
|
+
info(...args: any[]): void;
|
|
36
|
+
log(...args: any[]): void;
|
|
37
|
+
warn(...args: any[]): void;
|
|
38
|
+
error(...args: any[]): void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The central trunk from which all channels branch.
|
|
42
|
+
* Changing the filter here determines what kind of messages are printed across the app.
|
|
43
|
+
*/
|
|
44
|
+
export declare class DebugHub {
|
|
45
|
+
#private;
|
|
46
|
+
constructor(options: DebugHubOptions, _console?: any);
|
|
47
|
+
/**
|
|
48
|
+
* Returns a debug channel labelled by `name`. Used for logging from components.
|
|
49
|
+
*/
|
|
50
|
+
channel(options: DebugChannelOptions): DebugChannel;
|
|
51
|
+
get filter(): string | RegExp;
|
|
52
|
+
set filter(pattern: string | RegExp);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parses a filter string into a match function.
|
|
56
|
+
*
|
|
57
|
+
* @param pattern - A string or regular expression that specifies a pattern for names of debug channels you want to display.
|
|
58
|
+
*/
|
|
59
|
+
export declare function makeMatcher(pattern: string | RegExp): (value: string) => boolean;
|
|
60
|
+
export {};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { makeApp } from "./app.js";
|
|
2
|
+
export { spring } from "./spring.js";
|
|
3
|
+
export { readable, writable, computed, proxy, observe, unwrap, isReadable, isWritable } from "./state.js";
|
|
4
|
+
export { m, cond, repeat, portal } from "./markup.js";
|
|
5
|
+
export { Fragment } from "./views/fragment.js";
|
|
6
|
+
export { StoreScope } from "./views/store-scope.js";
|
|
7
|
+
export type { DialogProps } from "./stores/dialog.js";
|
|
8
|
+
export type { StoreScopeProps } from "./views/store-scope.js";
|
|
9
|
+
export type { Spring } from "./spring.js";
|
|
10
|
+
export type { Readable, Writable } from "./state.js";
|
|
11
|
+
export type { ViewContext } from "./view.js";
|
|
12
|
+
export type { StoreContext } from "./store.js";
|
|
13
|
+
export type { Markup } from "./markup.js";
|
|
14
|
+
export type { HTTPMiddleware } from "./stores/http.js";
|
|
15
|
+
export type { InputType } from "./types.js";
|
|
16
|
+
import type { IntrinsicElements as Elements } from "./types";
|
|
17
|
+
declare global {
|
|
18
|
+
namespace JSX {
|
|
19
|
+
interface IntrinsicElements extends Elements {
|
|
20
|
+
[tag: string]: any;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|