@manyducks.co/dolla 2.0.0-alpha.51 → 2.0.0-alpha.52
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 +15 -11
- package/dist/core/context.d.ts +7 -3
- package/dist/core/env.d.ts +9 -0
- package/dist/core/index.d.ts +23 -0
- package/dist/core/logger.d.ts +34 -0
- package/dist/core/markup.d.ts +6 -11
- package/dist/core/mount.d.ts +10 -0
- package/dist/core/nodes/dynamic.d.ts +1 -1
- package/dist/core/nodes/fragment.d.ts +1 -1
- package/dist/core/nodes/outlet.d.ts +1 -1
- package/dist/core/nodes/repeat.d.ts +1 -1
- package/dist/core/nodes/view.d.ts +11 -6
- package/dist/core/signals.d.ts +43 -2
- package/dist/core/store.d.ts +10 -5
- package/dist/{fragment-Bvuvw3ue.js → fragment-DSGTP-XE.js} +2 -2
- package/dist/{fragment-Bvuvw3ue.js.map → fragment-DSGTP-XE.js.map} +1 -1
- package/dist/http.js +163 -0
- package/dist/http.js.map +1 -0
- package/dist/{translate → i18n}/index.d.ts +7 -6
- package/dist/i18n.js +318 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.js +63 -1190
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/logger-CSRDjb4e.js +623 -0
- package/dist/logger-CSRDjb4e.js.map +1 -0
- package/dist/router/index.d.ts +1 -144
- package/dist/router/router.d.ts +139 -0
- package/dist/router-BYOH-To5.js +482 -0
- package/dist/router-BYOH-To5.js.map +1 -0
- package/dist/router.js +8 -0
- package/dist/router.js.map +1 -0
- package/dist/typeChecking-EAVNeFyB.js +75 -0
- package/dist/typeChecking-EAVNeFyB.js.map +1 -0
- package/dist/types.d.ts +9 -1
- package/dist/view-CY19Cf0X.js +932 -0
- package/dist/view-CY19Cf0X.js.map +1 -0
- package/docs/markup.md +16 -0
- package/notes/stores.md +26 -0
- package/package.json +14 -2
- package/vite.config.js +4 -5
- package/dist/core/dolla.d.ts +0 -128
- package/dist/core/signals-api.d.ts +0 -42
- package/dist/index.d.ts +0 -26
- package/dist/markup-QqAGIoYP.js +0 -1501
- package/dist/markup-QqAGIoYP.js.map +0 -1
- /package/dist/core/{signals-api.test.d.ts → signals.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -35,30 +35,34 @@ Dolla's goals include:
|
|
|
35
35
|
A basic view. Note that the view function is called exactly once when the view is first mounted. All changes to DOM nodes thereafter happen as a result of `$state` values changing.
|
|
36
36
|
|
|
37
37
|
```jsx
|
|
38
|
-
import
|
|
38
|
+
import { $, when, mount } from "@manyducks.co/dolla";
|
|
39
39
|
|
|
40
40
|
function Counter(props, ctx) {
|
|
41
|
-
const count = $(0);
|
|
41
|
+
const $count = $(0);
|
|
42
42
|
|
|
43
43
|
// An effect will re-run whenever any signal value accessed inside it changes.
|
|
44
44
|
ctx.effect(() => {
|
|
45
|
-
console.log(`Count is: ${count()}`);
|
|
45
|
+
console.log(`Count is: ${$count()}`);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
function increment() {
|
|
49
|
-
//
|
|
50
|
-
count(
|
|
49
|
+
// Pass a function that takes the current value and returns a new one.
|
|
50
|
+
$count((x) => x + 1);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function decrement() {
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
$count((x) => x - 1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function reset() {
|
|
58
|
+
// Set state directly by passing a (non-function) value.
|
|
59
|
+
$count(0);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
return (
|
|
59
63
|
<div>
|
|
60
64
|
{/* Signals can be slotted into the DOM to render them */}
|
|
61
|
-
<p>Counter: {count}</p>
|
|
65
|
+
<p>Counter: {$count}</p>
|
|
62
66
|
<div>
|
|
63
67
|
<button on:click={increment}>+1</button>
|
|
64
68
|
<button on:click={decrement}>-1</button>
|
|
@@ -66,7 +70,7 @@ function Counter(props, ctx) {
|
|
|
66
70
|
|
|
67
71
|
{/* We can derive a new signal on the fly and conditionally render something based on that condition */}
|
|
68
72
|
{when(
|
|
69
|
-
$(() => count() > 10),
|
|
73
|
+
$(() => $count() > 10),
|
|
70
74
|
<span>That's a lot of clicks!</span>,
|
|
71
75
|
)}
|
|
72
76
|
|
|
@@ -76,7 +80,7 @@ function Counter(props, ctx) {
|
|
|
76
80
|
// If we get Dynamic to track its rendered elements and diff them by keys
|
|
77
81
|
// then we may be able to do away with repeat and when and just do things like:
|
|
78
82
|
// <ul>{() => items().map(item => <li>{item}</li>)}</ul>
|
|
79
|
-
if (count() > 10) {
|
|
83
|
+
if ($count() > 10) {
|
|
80
84
|
return <span>That's a lot of clicks!</span>;
|
|
81
85
|
}
|
|
82
86
|
}}
|
|
@@ -84,7 +88,7 @@ function Counter(props, ctx) {
|
|
|
84
88
|
);
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
mount(document.body, Counter);
|
|
88
92
|
```
|
|
89
93
|
|
|
90
94
|
> TODO: Show small examples for routing and stores.
|
package/dist/core/context.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { Dolla } from "./dolla";
|
|
2
1
|
import type { View } from "./nodes/view";
|
|
3
|
-
import type { Source } from "./signals
|
|
2
|
+
import type { Source } from "./signals";
|
|
4
3
|
import type { Store, StoreFunction } from "./store";
|
|
5
4
|
export interface ElementContext {
|
|
6
5
|
/**
|
|
7
6
|
* The root Dolla instance this element belongs to.
|
|
8
7
|
*/
|
|
9
|
-
root: Dolla;
|
|
10
8
|
/**
|
|
11
9
|
* Stores attached to this context.
|
|
12
10
|
*/
|
|
@@ -63,3 +61,9 @@ export interface StoreConsumerContext {
|
|
|
63
61
|
*/
|
|
64
62
|
get<Value>(store: StoreFunction<any, Value>): Value;
|
|
65
63
|
}
|
|
64
|
+
type StoreMap = Map<any, any>;
|
|
65
|
+
export declare const globalStores: StoreMap;
|
|
66
|
+
export declare const rootElementContext: {
|
|
67
|
+
stores: StoreMap;
|
|
68
|
+
};
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type Env = "production" | "development";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the current environment value.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getEnv(): Env;
|
|
6
|
+
/**
|
|
7
|
+
* Sets the environment value. Affects which log messages will print and how much debugging info is included in the DOM.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setEnv(value: Env): void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export { $, effect, get, peek } from "./signals.js";
|
|
2
|
+
export type { MaybeSignal, Signal, Source } from "./signals.js";
|
|
3
|
+
export { constructView } from "./nodes/view.js";
|
|
4
|
+
export { deepEqual, shallowEqual, strictEqual } from "../utils.js";
|
|
5
|
+
export { Stores, type StoreContext, type StoreFunction } from "./store.js";
|
|
6
|
+
export { markup, portal, repeat, unless, when, constructMarkup } from "./markup.js";
|
|
7
|
+
export type { Markup, MarkupElement } from "./markup.js";
|
|
8
|
+
export { getEnv, setEnv } from "./env.js";
|
|
9
|
+
export type { Env } from "./env.js";
|
|
10
|
+
export { createLogger, setLogFilter, setLogLevels } from "./logger.js";
|
|
11
|
+
export type { Logger, LoggerErrorContext, LoggerOptions, LogLevels } from "./logger.js";
|
|
12
|
+
export { mount, type UnmountFn } from "./mount.js";
|
|
13
|
+
export type { ViewContext, ViewElement, ViewFunction } from "./nodes/view.js";
|
|
14
|
+
export type { CrashViewProps } from "./views/default-crash-view.js";
|
|
15
|
+
export type { InputType, Renderable } from "../types.js";
|
|
16
|
+
import type { IntrinsicElements as Elements } from "../types.js";
|
|
17
|
+
declare global {
|
|
18
|
+
namespace JSX {
|
|
19
|
+
interface IntrinsicElements extends Elements {
|
|
20
|
+
[tag: string]: any;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Env } from "./env";
|
|
2
|
+
import { type MaybeSignal } from "./signals";
|
|
3
|
+
export interface LogLevels {
|
|
4
|
+
info: boolean | Env;
|
|
5
|
+
log: boolean | Env;
|
|
6
|
+
warn: boolean | Env;
|
|
7
|
+
error: boolean | Env;
|
|
8
|
+
}
|
|
9
|
+
export interface Logger {
|
|
10
|
+
info(...args: any[]): void;
|
|
11
|
+
log(...args: any[]): void;
|
|
12
|
+
warn(...args: any[]): void;
|
|
13
|
+
error(...args: any[]): void;
|
|
14
|
+
crash(error: Error): void;
|
|
15
|
+
}
|
|
16
|
+
export interface LoggerOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Unique ID to print with logs. Makes it easier to track down messages from specific view instances.
|
|
19
|
+
*/
|
|
20
|
+
uid?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Console object to use for logging (mostly for testing). Uses window.console by default.
|
|
23
|
+
*/
|
|
24
|
+
console?: any;
|
|
25
|
+
}
|
|
26
|
+
export interface LoggerErrorContext {
|
|
27
|
+
error: Error;
|
|
28
|
+
loggerName: string;
|
|
29
|
+
uid?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function onLoggerCrash(listener: (context: LoggerErrorContext) => void): () => void;
|
|
32
|
+
export declare function createLogger(name: MaybeSignal<string>, options?: LoggerOptions): Logger;
|
|
33
|
+
export declare function setLogFilter(filter: string | RegExp): void;
|
|
34
|
+
export declare function setLogLevels(options: Partial<LogLevels>): void;
|
package/dist/core/markup.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Renderable } from "../types.js";
|
|
2
|
-
import type
|
|
1
|
+
import type { Mountable, Renderable } from "../types.js";
|
|
2
|
+
import { type ElementContext } from "./context.js";
|
|
3
3
|
import { View, type ViewContext, type ViewFunction, type ViewResult } from "./nodes/view.js";
|
|
4
|
-
import { type MaybeSignal, type Signal } from "./signals
|
|
4
|
+
import { type MaybeSignal, type Signal } from "./signals.js";
|
|
5
5
|
/**
|
|
6
6
|
* Markup is a set of element metadata that hasn't been constructed into a MarkupElement yet.
|
|
7
7
|
*/
|
|
@@ -23,19 +23,14 @@ export interface Markup {
|
|
|
23
23
|
/**
|
|
24
24
|
* A DOM node that has been constructed from a Markup object.
|
|
25
25
|
*/
|
|
26
|
-
export interface MarkupElement {
|
|
26
|
+
export interface MarkupElement extends Mountable {
|
|
27
27
|
readonly domNode?: Node;
|
|
28
28
|
readonly isMounted: boolean;
|
|
29
|
-
mount(parent: Node, after?: Node): void;
|
|
30
|
-
/**
|
|
31
|
-
* Disconnect from the DOM and clean up. If parentIsUnmounting, DOM operations are skipped.
|
|
32
|
-
* parentIsUnmounting is set for all children by HTML nodes when they unmount.
|
|
33
|
-
*/
|
|
34
|
-
unmount(parentIsUnmounting?: boolean): void;
|
|
35
29
|
}
|
|
36
30
|
export declare function isMarkup(value: any): value is Markup;
|
|
37
31
|
export declare function isMarkupElement(value: any): value is MarkupElement;
|
|
38
32
|
export declare function toMarkup(renderables: Renderable | Renderable[]): Markup[];
|
|
33
|
+
export declare function constructMarkup(markup: Markup | Markup[]): MarkupElement;
|
|
39
34
|
export declare enum MarkupType {
|
|
40
35
|
Text = "$text",
|
|
41
36
|
Repeat = "$repeat",
|
|
@@ -94,7 +89,7 @@ export declare function portal(parent: Node, content: Renderable): Markup;
|
|
|
94
89
|
/**
|
|
95
90
|
* Construct Markup metadata into a set of MarkupElements.
|
|
96
91
|
*/
|
|
97
|
-
export declare function
|
|
92
|
+
export declare function toMarkupElements(elementContext: ElementContext, markup: Markup | Markup[]): MarkupElement[];
|
|
98
93
|
/**
|
|
99
94
|
* Combines one or more MarkupElements into a single MarkupElement.
|
|
100
95
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type LoggerErrorContext } from "./logger";
|
|
2
|
+
import { type ViewFunction } from "./nodes/view";
|
|
3
|
+
export type UnmountFn = () => Promise<void>;
|
|
4
|
+
export interface MountOptions {
|
|
5
|
+
crashView?: ViewFunction<LoggerErrorContext>;
|
|
6
|
+
}
|
|
7
|
+
export declare function mount(parent: Element, view: any, options?: MountOptions): Promise<UnmountFn>;
|
|
8
|
+
export declare function mount(parent: Element, router: any, options?: MountOptions): Promise<UnmountFn>;
|
|
9
|
+
export declare function mount(parent: string, view: any, options?: MountOptions): Promise<UnmountFn>;
|
|
10
|
+
export declare function mount(parent: string, router: any, options?: MountOptions): Promise<UnmountFn>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Renderable } from "../../types.js";
|
|
2
2
|
import type { ElementContext } from "../context.js";
|
|
3
3
|
import { type MarkupElement } from "../markup.js";
|
|
4
|
-
import { Signal } from "../signals
|
|
4
|
+
import { Signal } from "../signals.js";
|
|
5
5
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
6
6
|
interface DynamicOptions {
|
|
7
7
|
source: Signal<Renderable>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ElementContext } from "../context.js";
|
|
2
2
|
import { type MarkupElement } from "../markup.js";
|
|
3
|
-
import { type Signal } from "../signals
|
|
3
|
+
import { type Signal } from "../signals.js";
|
|
4
4
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
5
5
|
import { type ViewContext, type ViewResult } from "./view.js";
|
|
6
6
|
interface RepeatOptions<T> {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type
|
|
1
|
+
import { Renderable } from "../../types.js";
|
|
2
|
+
import { type ComponentContext, type ElementContext, type StoreConsumerContext, type StoreProviderContext } from "../context.js";
|
|
3
|
+
import { type Logger } from "../logger.js";
|
|
3
4
|
import { type Markup, type MarkupElement } from "../markup.js";
|
|
4
|
-
import { type
|
|
5
|
+
import { type EffectFn, type Signal, type UnsubscribeFn } from "../signals.js";
|
|
5
6
|
import { StoreFunction } from "../store.js";
|
|
6
7
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
7
8
|
/**
|
|
@@ -44,7 +45,7 @@ export interface ViewContext extends Omit<Logger, "setName">, ComponentContext,
|
|
|
44
45
|
* Passes a getter function to `callback` that will track reactive states and return their current values.
|
|
45
46
|
* Callback will be run each time a tracked state gets a new value.
|
|
46
47
|
*/
|
|
47
|
-
effect(callback:
|
|
48
|
+
effect(callback: EffectFn): UnsubscribeFn;
|
|
48
49
|
/**
|
|
49
50
|
* Displays this view's subroutes if mounted as a router view.
|
|
50
51
|
*/
|
|
@@ -65,7 +66,7 @@ declare class Context implements ViewContext {
|
|
|
65
66
|
onMount(callback: () => void): void;
|
|
66
67
|
beforeUnmount(callback: () => void): void;
|
|
67
68
|
onUnmount(callback: () => void): void;
|
|
68
|
-
effect(callback:
|
|
69
|
+
effect(callback: EffectFn): UnsubscribeFn;
|
|
69
70
|
outlet(): Markup;
|
|
70
71
|
}
|
|
71
72
|
export declare class View<P> implements ViewElement {
|
|
@@ -78,7 +79,7 @@ export declare class View<P> implements ViewElement {
|
|
|
78
79
|
};
|
|
79
80
|
fn: ViewFunction<P>;
|
|
80
81
|
element?: MarkupElement;
|
|
81
|
-
name: string
|
|
82
|
+
name: import("../signals.js").Source<string>;
|
|
82
83
|
context: Context;
|
|
83
84
|
lifecycleListeners: {
|
|
84
85
|
beforeMount: (() => any)[];
|
|
@@ -94,4 +95,8 @@ export declare class View<P> implements ViewElement {
|
|
|
94
95
|
setRouteView(fn: ViewFunction<{}>): View<{}>;
|
|
95
96
|
private _initialize;
|
|
96
97
|
}
|
|
98
|
+
export declare function constructView<P>(view: ViewFunction<P>, props: P, children?: Renderable[]): ViewElement;
|
|
99
|
+
export declare function constructView(view: ViewFunction<{}>, children?: Renderable[]): ViewElement;
|
|
100
|
+
export declare function constructView<P>(context: ElementContext, view: ViewFunction<P>, props: P, children?: Renderable[]): ViewElement;
|
|
101
|
+
export declare function constructView(context: ElementContext, view: ViewFunction<{}>, children?: Renderable[]): ViewElement;
|
|
97
102
|
export {};
|
package/dist/core/signals.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type Dependency, type Subscriber, SubscriberFlags } from "alien-signals";
|
|
2
|
-
import type { EqualityFunction } from "./signals-api";
|
|
3
2
|
export interface Effect extends Subscriber, Dependency {
|
|
4
3
|
/**
|
|
5
4
|
* Effect function. Can return an optional cleanup callback to be invoked before the next fn() call.
|
|
@@ -9,7 +8,7 @@ export interface Effect extends Subscriber, Dependency {
|
|
|
9
8
|
}
|
|
10
9
|
export interface Computed<T = any> extends Value<T | undefined>, Subscriber {
|
|
11
10
|
getter: (cachedValue?: T) => T;
|
|
12
|
-
equals:
|
|
11
|
+
equals: EqualityFn<T>;
|
|
13
12
|
}
|
|
14
13
|
export interface Value<T = any> extends Dependency {
|
|
15
14
|
current: T;
|
|
@@ -20,3 +19,45 @@ export declare function queueEffect(e: Effect): void;
|
|
|
20
19
|
export declare function stopEffect(this: Effect): void;
|
|
21
20
|
export declare function pauseTracking(): void;
|
|
22
21
|
export declare function resumeTracking(): void;
|
|
22
|
+
/**
|
|
23
|
+
* A getter that returns the current value held within the signal.
|
|
24
|
+
* If called inside a trackable scope this signal will be tracked as a dependency.
|
|
25
|
+
*/
|
|
26
|
+
export interface Signal<T> {
|
|
27
|
+
(): T;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extends Signal with the ability to pass a value or an updater function to change the Signal's value.
|
|
31
|
+
*/
|
|
32
|
+
export interface Source<T> extends Signal<T> {
|
|
33
|
+
(value: T): void;
|
|
34
|
+
(updater: (value: T) => T): void;
|
|
35
|
+
}
|
|
36
|
+
export type MaybeSignal<T> = Signal<T> | T;
|
|
37
|
+
export type EqualityFn<T> = (current: T, next: T) => boolean;
|
|
38
|
+
export interface SignalOptions<T> {
|
|
39
|
+
/**
|
|
40
|
+
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
41
|
+
*/
|
|
42
|
+
equals?: EqualityFn<T>;
|
|
43
|
+
}
|
|
44
|
+
export declare function isSource<T>(value: MaybeSignal<T>): value is Source<T>;
|
|
45
|
+
export declare function peek<T>(value: MaybeSignal<T>): T;
|
|
46
|
+
export declare function get<T>(value: MaybeSignal<T>): T;
|
|
47
|
+
/**
|
|
48
|
+
* Function to be invoked for the effect. Can return an optional cleanup function to be called between invocations.
|
|
49
|
+
*/
|
|
50
|
+
export type EffectFn = () => void | (() => void);
|
|
51
|
+
export type UnsubscribeFn = () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a tracked scope that re-runs whenever the values of any tracked reactives changes.
|
|
54
|
+
* Reactives are tracked by accessing their `value` within the body of the function.
|
|
55
|
+
*
|
|
56
|
+
* NOTE: You must call the unsubscribe function to stop watching for changes.
|
|
57
|
+
* If you are using an effect inside a View or Store, use `ctx.effect` instead, which cleans up automatically when the component unmounts.
|
|
58
|
+
*/
|
|
59
|
+
export declare function effect(fn: EffectFn): UnsubscribeFn;
|
|
60
|
+
export declare function $<T>(compute: () => MaybeSignal<T>, options?: SignalOptions<T>): Signal<T>;
|
|
61
|
+
export declare function $<T>(value: T, options?: SignalOptions<T>): Source<T>;
|
|
62
|
+
export declare function $<T>(value: undefined, options?: SignalOptions<T>): Source<T | undefined>;
|
|
63
|
+
export declare function $<T>(): Source<T | undefined>;
|
package/dist/core/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import { type
|
|
1
|
+
import { type ComponentContext, type ElementContext, type StoreConsumerContext, type StoreProviderContext } from "./context.js";
|
|
2
|
+
import { type Logger } from "./logger.js";
|
|
3
|
+
import { type EffectFn, type UnsubscribeFn } from "./signals.js";
|
|
4
4
|
export type StoreFunction<Options, Value> = (this: StoreContext, options: Options, context: StoreContext) => Value;
|
|
5
5
|
export type StoreFactory<Options, Value> = Options extends undefined ? () => Store<Options, Value> : (options: Options) => Store<Options, Value>;
|
|
6
6
|
export interface StoreContext extends Omit<Logger, "setName">, ComponentContext, StoreConsumerContext {
|
|
@@ -20,7 +20,7 @@ export interface StoreContext extends Omit<Logger, "setName">, ComponentContext,
|
|
|
20
20
|
* Passes a getter function to `callback` that will track reactive states and return their current values.
|
|
21
21
|
* Callback will be run each time a tracked state gets a new value.
|
|
22
22
|
*/
|
|
23
|
-
effect(callback:
|
|
23
|
+
effect(callback: EffectFn): UnsubscribeFn;
|
|
24
24
|
}
|
|
25
25
|
export declare class Store<Options, Value> {
|
|
26
26
|
readonly fn: StoreFunction<Options, Value>;
|
|
@@ -37,7 +37,7 @@ export declare class Store<Options, Value> {
|
|
|
37
37
|
};
|
|
38
38
|
logger: Logger;
|
|
39
39
|
id: string;
|
|
40
|
-
name: string
|
|
40
|
+
name: import("./signals.js").Source<string>;
|
|
41
41
|
constructor(fn: StoreFunction<Options, Value>, options: Options);
|
|
42
42
|
/**
|
|
43
43
|
* Attaches this Store to the elementContext.
|
|
@@ -50,3 +50,8 @@ export declare class Store<Options, Value> {
|
|
|
50
50
|
export declare function isStore<Options, Value>(value: any): value is Store<Options, Value>;
|
|
51
51
|
export declare class StoreError extends Error {
|
|
52
52
|
}
|
|
53
|
+
export type Stores = StoreProviderContext & StoreConsumerContext;
|
|
54
|
+
/**
|
|
55
|
+
* Global store registry.
|
|
56
|
+
*/
|
|
57
|
+
export declare const Stores: Stores;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { m } from "./
|
|
1
|
+
import { m } from "./view-CY19Cf0X.js";
|
|
2
2
|
function a(r, n) {
|
|
3
3
|
return m("$dynamic", { source: () => r.children });
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
6
|
a as F
|
|
7
7
|
};
|
|
8
|
-
//# sourceMappingURL=fragment-
|
|
8
|
+
//# sourceMappingURL=fragment-DSGTP-XE.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragment-
|
|
1
|
+
{"version":3,"file":"fragment-DSGTP-XE.js","sources":["../src/core/views/fragment.ts"],"sourcesContent":["import type { Renderable } from \"../../types.js\";\nimport { markup } from \"../markup.js\";\nimport { type ViewContext } from \"../nodes/view.js\";\n\n/**\n * A utility view that displays its children.\n */\nexport function Fragment(props: { children?: Renderable }, ctx: ViewContext) {\n return markup(\"$dynamic\", { source: () => props.children });\n}\n"],"names":["Fragment","props","ctx","markup"],"mappings":";AAOgB,SAAAA,EAASC,GAAkCC,GAAkB;AAC3E,SAAOC,EAAO,YAAY,EAAE,QAAQ,MAAMF,EAAM,UAAU;AAC5D;"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var f = (r) => {
|
|
3
|
+
throw TypeError(r);
|
|
4
|
+
};
|
|
5
|
+
var g = (r, e, t) => e in r ? b(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
6
|
+
var a = (r, e, t) => g(r, typeof e != "symbol" ? e + "" : e, t), m = (r, e, t) => e.has(r) || f("Cannot " + t);
|
|
7
|
+
var d = (r, e, t) => (m(r, e, "read from private field"), t ? t.call(r) : e.get(r)), c = (r, e, t) => e.has(r) ? f("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t);
|
|
8
|
+
var o = (r, e, t) => (m(r, e, "access private method"), t);
|
|
9
|
+
import { b as w } from "./typeChecking-EAVNeFyB.js";
|
|
10
|
+
var l, p, i, h;
|
|
11
|
+
class O {
|
|
12
|
+
constructor() {
|
|
13
|
+
c(this, i);
|
|
14
|
+
c(this, l, []);
|
|
15
|
+
c(this, p, S());
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Adds a new middleware that will apply to subsequent requests.
|
|
19
|
+
* Returns a function to remove this middleware.
|
|
20
|
+
*
|
|
21
|
+
* @param middleware - A middleware function that will intercept requests.
|
|
22
|
+
*/
|
|
23
|
+
use(e) {
|
|
24
|
+
return d(this, l).push(e), () => {
|
|
25
|
+
d(this, l).splice(d(this, l).indexOf(e), 1);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async get(e, t) {
|
|
29
|
+
return o(this, i, h).call(this, "get", e, t);
|
|
30
|
+
}
|
|
31
|
+
async put(e, t) {
|
|
32
|
+
return o(this, i, h).call(this, "put", e, t);
|
|
33
|
+
}
|
|
34
|
+
async patch(e, t) {
|
|
35
|
+
return o(this, i, h).call(this, "patch", e, t);
|
|
36
|
+
}
|
|
37
|
+
async post(e, t) {
|
|
38
|
+
return o(this, i, h).call(this, "post", e, t);
|
|
39
|
+
}
|
|
40
|
+
async delete(e, t) {
|
|
41
|
+
return o(this, i, h).call(this, "delete", e, t);
|
|
42
|
+
}
|
|
43
|
+
async head(e, t) {
|
|
44
|
+
return o(this, i, h).call(this, "head", e, t);
|
|
45
|
+
}
|
|
46
|
+
async options(e, t) {
|
|
47
|
+
return o(this, i, h).call(this, "options", e, t);
|
|
48
|
+
}
|
|
49
|
+
async trace(e, t) {
|
|
50
|
+
return o(this, i, h).call(this, "trace", e, t);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
l = new WeakMap(), p = new WeakMap(), i = new WeakSet(), h = async function(e, t, s) {
|
|
54
|
+
return new x({
|
|
55
|
+
...s,
|
|
56
|
+
method: e,
|
|
57
|
+
uri: t,
|
|
58
|
+
middleware: d(this, l),
|
|
59
|
+
fetch: d(this, p)
|
|
60
|
+
}).fetch();
|
|
61
|
+
};
|
|
62
|
+
function S() {
|
|
63
|
+
if (typeof window < "u" && window.fetch)
|
|
64
|
+
return window.fetch.bind(window);
|
|
65
|
+
if (typeof global < "u" && global.fetch)
|
|
66
|
+
return global.fetch.bind(global);
|
|
67
|
+
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
68
|
+
}
|
|
69
|
+
class P extends Error {
|
|
70
|
+
constructor(t) {
|
|
71
|
+
const { status: s, statusText: n, method: u, url: y } = t, _ = `${s} ${n}: Request failed (${u.toUpperCase()} ${y.toString()})`;
|
|
72
|
+
super(_);
|
|
73
|
+
a(this, "response");
|
|
74
|
+
this.response = t;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
class R {
|
|
78
|
+
constructor(e) {
|
|
79
|
+
a(this, "method");
|
|
80
|
+
a(this, "url");
|
|
81
|
+
a(this, "headers", new Headers());
|
|
82
|
+
a(this, "body");
|
|
83
|
+
this.method = e.method, this.body = e.body, e.uri.startsWith("http") ? this.url = new URL(e.uri) : this.url = new URL(e.uri, window.location.origin), this._applyHeaders(e.headers), this._applyQueryParams(e.query);
|
|
84
|
+
}
|
|
85
|
+
get isSameOrigin() {
|
|
86
|
+
return this.url.origin === window.location.origin;
|
|
87
|
+
}
|
|
88
|
+
_applyHeaders(e) {
|
|
89
|
+
if (e != null)
|
|
90
|
+
if (e instanceof Map || e instanceof Headers)
|
|
91
|
+
e.forEach((t, s) => {
|
|
92
|
+
this.headers.set(s, t);
|
|
93
|
+
});
|
|
94
|
+
else if (w(e))
|
|
95
|
+
for (const t in e) {
|
|
96
|
+
const s = e[t];
|
|
97
|
+
s instanceof Date ? this.headers.set(t, s.toISOString()) : s != null && this.headers.set(t, String(s));
|
|
98
|
+
}
|
|
99
|
+
else
|
|
100
|
+
throw new TypeError(`Unknown headers type. Got: ${e}`);
|
|
101
|
+
}
|
|
102
|
+
_applyQueryParams(e) {
|
|
103
|
+
if (e != null)
|
|
104
|
+
if (e instanceof Map || e instanceof URLSearchParams)
|
|
105
|
+
e.forEach((t, s) => {
|
|
106
|
+
this.url.searchParams.set(s, t);
|
|
107
|
+
});
|
|
108
|
+
else if (w(e))
|
|
109
|
+
for (const t in e) {
|
|
110
|
+
const s = e[t];
|
|
111
|
+
s instanceof Date ? this.url.searchParams.set(t, s.toISOString()) : s != null && this.url.searchParams.set(t, String(s));
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
throw new TypeError(`Unknown query params type. Got: ${e}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
class x {
|
|
118
|
+
constructor(e) {
|
|
119
|
+
a(this, "_middleware");
|
|
120
|
+
a(this, "_fetch");
|
|
121
|
+
a(this, "_request");
|
|
122
|
+
a(this, "_response");
|
|
123
|
+
this._middleware = e.middleware, this._fetch = e.fetch, this._request = new R(e);
|
|
124
|
+
}
|
|
125
|
+
async fetch() {
|
|
126
|
+
if (this._middleware.length > 0) {
|
|
127
|
+
const e = (t = 0) => {
|
|
128
|
+
const s = this._middleware[t], n = this._middleware[t + 1] ? e(t + 1) : this._handler.bind(this);
|
|
129
|
+
return async () => s(this._request, async () => (await n(), this._response));
|
|
130
|
+
};
|
|
131
|
+
await e()();
|
|
132
|
+
} else
|
|
133
|
+
await this._handler();
|
|
134
|
+
if (this._response.status < 200 || this._response.status >= 400)
|
|
135
|
+
throw new P(this._response);
|
|
136
|
+
return this._response;
|
|
137
|
+
}
|
|
138
|
+
// This is the function that performs the actual request after the final middleware.
|
|
139
|
+
async _handler() {
|
|
140
|
+
let e;
|
|
141
|
+
const t = this._request;
|
|
142
|
+
!t.headers.has("content-type") && w(t.body) ? (t.headers.set("content-type", "application/json"), e = JSON.stringify(t.body)) : e = t.body;
|
|
143
|
+
const s = await this._fetch(t.url.toString(), {
|
|
144
|
+
method: t.method,
|
|
145
|
+
headers: t.headers,
|
|
146
|
+
body: e
|
|
147
|
+
}), n = s.headers.get("content-type");
|
|
148
|
+
let u;
|
|
149
|
+
n != null && n.includes("application/json") ? u = await s.json() : n != null && n.includes("application/x-www-form-urlencoded") ? u = await s.formData() : u = await s.text(), this._response = {
|
|
150
|
+
method: t.method,
|
|
151
|
+
url: t.url,
|
|
152
|
+
status: s.status,
|
|
153
|
+
statusText: s.statusText,
|
|
154
|
+
headers: s.headers,
|
|
155
|
+
body: u
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
O as HTTP,
|
|
161
|
+
P as HTTPResponseError
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sources":["../src/http/index.ts"],"sourcesContent":["import { isObject } from \"../typeChecking.js\";\n\n/**\n * A simple HTTP client with middleware support. Middleware applies to all requests made through this store,\n * so it's the perfect way to handle things like auth headers and permission checks for API calls.\n */\nexport class HTTP {\n #middleware: HTTPMiddleware[] = [];\n #fetch = getDefaultFetch();\n\n /**\n * Adds a new middleware that will apply to subsequent requests.\n * Returns a function to remove this middleware.\n *\n * @param middleware - A middleware function that will intercept requests.\n */\n use(fn: HTTPMiddleware) {\n this.#middleware.push(fn);\n\n // Call returned function to remove this middleware for subsequent requests.\n return () => {\n this.#middleware.splice(this.#middleware.indexOf(fn), 1);\n };\n }\n\n async get<ResBody = unknown>(uri: string, options?: RequestOptions<never>) {\n return this.#request<ResBody, never>(\"get\", uri, options);\n }\n\n async put<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"put\", uri, options);\n }\n\n async patch<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"patch\", uri, options);\n }\n\n async post<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"post\", uri, options);\n }\n\n async delete<ResBody = unknown>(uri: string, options?: RequestOptions<never>) {\n return this.#request<ResBody, never>(\"delete\", uri, options);\n }\n\n async head<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"head\", uri, options);\n }\n\n async options<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"options\", uri, options);\n }\n\n async trace<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>) {\n return this.#request<ResBody, ReqBody>(\"trace\", uri, options);\n }\n\n async #request<ResBody, ReqBody>(method: string, uri: string, options?: RequestOptions<any>) {\n const runner = new Runner<ResBody, ReqBody>({\n ...options,\n method,\n uri,\n middleware: this.#middleware,\n fetch: this.#fetch,\n });\n return runner.fetch();\n }\n}\n\nfunction getDefaultFetch(): typeof window.fetch {\n if (typeof window !== \"undefined\" && window.fetch) {\n return window.fetch.bind(window);\n }\n\n if (typeof global !== \"undefined\" && global.fetch) {\n return global.fetch.bind(global);\n }\n\n throw new Error(\"Running in neither browser nor node. Please run this app in one of the supported environments.\");\n}\n\n/*====================*\\\n|| Request ||\n\\*====================*/\n\nexport type HTTPMiddleware = (\n request: HTTPRequest<unknown>,\n next: () => Promise<HTTPResponse<unknown>>,\n) => void | Promise<void>;\n\nexport interface RequestOptions<ReqBody> {\n /**\n * Body to send with the request.\n */\n body?: ReqBody;\n\n /**\n * Headers to send with the request.\n */\n headers?: Record<string, any> | Headers;\n\n /**\n * Query params to interpolate into the URL.\n */\n query?: Record<string, any> | URLSearchParams;\n}\n\nexport interface HTTPRequest<Body> {\n method: string;\n url: URL;\n headers: Headers;\n body: Body;\n}\n\nexport interface HTTPResponse<Body> {\n method: string;\n url: URL;\n headers: Headers;\n status: number;\n statusText: string;\n body: Body;\n}\n\ninterface MakeRequestConfig<ReqBody> extends RequestOptions<ReqBody> {\n method: string;\n uri: string;\n middleware: HTTPMiddleware[];\n fetch: typeof window.fetch;\n}\n\nexport class HTTPResponseError extends Error {\n response;\n\n constructor(response: HTTPResponse<any>) {\n const { status, statusText, method, url } = response;\n const message = `${status} ${statusText}: Request failed (${method.toUpperCase()} ${url.toString()})`;\n\n super(message);\n\n this.response = response;\n }\n}\n\nclass Request<ReqBody> implements HTTPRequest<ReqBody> {\n method: string;\n url: URL;\n headers = new Headers();\n body!: ReqBody;\n\n get isSameOrigin() {\n return this.url.origin === window.location.origin;\n }\n\n constructor(config: MakeRequestConfig<ReqBody>) {\n this.method = config.method;\n this.body = config.body!;\n if (config.uri.startsWith(\"http\")) {\n this.url = new URL(config.uri);\n } else {\n this.url = new URL(config.uri, window.location.origin);\n }\n\n this._applyHeaders(config.headers);\n this._applyQueryParams(config.query);\n }\n\n private _applyHeaders(headers: any) {\n if (headers == null) return;\n\n if (headers instanceof Map || headers instanceof Headers) {\n headers.forEach((value, key) => {\n this.headers.set(key, value);\n });\n } else if (isObject(headers)) {\n for (const name in headers) {\n const value = headers[name];\n if (value instanceof Date) {\n this.headers.set(name, value.toISOString());\n } else if (value != null) {\n this.headers.set(name, String(value));\n }\n }\n } else {\n throw new TypeError(`Unknown headers type. Got: ${headers}`);\n }\n }\n\n private _applyQueryParams(query: any) {\n if (query == null) return;\n\n if (query instanceof Map || query instanceof URLSearchParams) {\n query.forEach((value, key) => {\n this.url.searchParams.set(key, value);\n });\n } else if (isObject(query)) {\n for (const name in query) {\n const value = query[name];\n if (value instanceof Date) {\n this.url.searchParams.set(name, value.toISOString());\n } else if (value != null) {\n this.url.searchParams.set(name, String(value));\n }\n }\n } else {\n throw new TypeError(`Unknown query params type. Got: ${query}`);\n }\n }\n}\n\nclass Runner<ResBody, ReqBody> {\n private _middleware;\n private _fetch;\n\n private _request: Request<ReqBody>;\n private _response?: HTTPResponse<ResBody>;\n\n constructor(config: MakeRequestConfig<ReqBody>) {\n this._middleware = config.middleware;\n this._fetch = config.fetch;\n\n this._request = new Request(config);\n }\n\n async fetch() {\n if (this._middleware.length > 0) {\n const mount = (index = 0) => {\n const current = this._middleware[index];\n const next = this._middleware[index + 1] ? mount(index + 1) : this._handler.bind(this);\n\n return async () =>\n current(this._request, async () => {\n await next();\n return this._response!;\n });\n };\n\n await mount()();\n } else {\n await this._handler();\n }\n\n if (this._response!.status < 200 || this._response!.status >= 400) {\n throw new HTTPResponseError(this._response!);\n }\n\n return this._response!;\n }\n\n // This is the function that performs the actual request after the final middleware.\n private async _handler() {\n let reqBody: BodyInit;\n\n const req = this._request;\n\n if (!req.headers.has(\"content-type\") && isObject(req.body)) {\n // Auto-detect JSON bodies and encode as a string with correct headers.\n req.headers.set(\"content-type\", \"application/json\");\n reqBody = JSON.stringify(req.body);\n } else {\n reqBody = req.body as BodyInit;\n }\n\n const fetched = await this._fetch(req.url.toString(), {\n method: req.method,\n headers: req.headers,\n body: reqBody,\n });\n\n // Auto-parse response body based on content-type header\n const contentType = fetched.headers.get(\"content-type\");\n\n let body: ResBody;\n\n if (contentType?.includes(\"application/json\")) {\n body = await fetched.json();\n } else if (contentType?.includes(\"application/x-www-form-urlencoded\")) {\n body = (await fetched.formData()) as ResBody;\n } else {\n body = (await fetched.text()) as ResBody;\n }\n\n this._response = {\n method: req.method,\n url: req.url,\n status: fetched.status,\n statusText: fetched.statusText,\n headers: fetched.headers,\n body,\n };\n }\n}\n"],"names":["HTTP","__privateAdd","_HTTP_instances","_middleware","_fetch","getDefaultFetch","fn","__privateGet","uri","options","__privateMethod","request_fn","method","Runner","HTTPResponseError","response","status","statusText","url","message","__publicField","Request","config","headers","value","key","isObject","name","query","mount","index","current","next","reqBody","req","fetched","contentType","body"],"mappings":";;;;;;;;;;AAMO,MAAMA,EAAK;AAAA,EAAX;AAAA,IAAAC,EAAA,MAAAC;AACL,IAAAD,EAAA,MAAAE,GAAgC,CAAC;AACjC,IAAAF,EAAA,MAAAG,GAASC,EAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQzB,IAAIC,GAAoB;AACjB,WAAAC,EAAA,MAAAJ,GAAY,KAAKG,CAAE,GAGjB,MAAM;AACX,MAAAC,EAAA,MAAKJ,GAAY,OAAOI,EAAA,MAAKJ,GAAY,QAAQG,CAAE,GAAG,CAAC;AAAA,IACzD;AAAA,EAAA;AAAA,EAGF,MAAM,IAAuBE,GAAaC,GAAiC;AACzE,WAAOC,EAAA,MAAKR,GAAAS,GAAL,WAA8B,OAAOH,GAAKC;AAAA,EAAO;AAAA,EAG1D,MAAM,IAA0CD,GAAaC,GAAmC;AAC9F,WAAOC,EAAA,MAAKR,GAAAS,GAAL,WAAgC,OAAOH,GAAKC;AAAA,EAAO;AAAA,EAG5D,MAAM,MAA4CD,GAAaC,GAAmC;AAChG,WAAOC,EAAA,MAAKR,GAAAS,GAAL,WAAgC,SAASH,GAAKC;AAAA,EA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KR,EAASQ,EAAI,IAAI,KAEnDA,EAAA,QAAQ,IAAI,gBAAgB,kBAAkB,GACxCD,IAAA,KAAK,UAAUC,EAAI,IAAI,KAEjCD,IAAUC,EAAI;AAGhB,UAAMC,IAAU,MAAM,KAAK,OAAOD,EAAI,IAAI,YAAY;AAAA,MACpD,QAAQA,EAAI;AAAA,MACZ,SAASA,EAAI;AAAA,MACb,MAAMD;AAAA,IAAA,CACP,GAGKG,IAAcD,EAAQ,QAAQ,IAAI,cAAc;AAElD,QAAAE;AAEA,IAAAD,KAAA,QAAAA,EAAa,SAAS,sBACjBC,IAAA,MAAMF,EAAQ,KAAK,IACjBC,KAAA,QAAAA,EAAa,SAAS,uCACvBC,IAAA,MAAMF,EAAQ,SAAS,IAEvBE,IAAA,MAAMF,EAAQ,KAAK,GAG7B,KAAK,YAAY;AAAA,MACf,QAAQD,EAAI;AAAA,MACZ,KAAKA,EAAI;AAAA,MACT,QAAQC,EAAQ;AAAA,MAChB,YAAYA,EAAQ;AAAA,MACpB,SAASA,EAAQ;AAAA,MACjB,MAAAE;AAAA,IACF;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type MaybeSignal, type Signal } from "../core/signals-api.js";
|
|
1
|
+
import { type MaybeSignal, type Signal } from "../core/signals.js";
|
|
3
2
|
/**
|
|
4
3
|
* A JSON object of translated strings. Values can be string templates or nested objects.
|
|
5
4
|
*/
|
|
@@ -64,12 +63,12 @@ export type Formatter = (locale: string, value: unknown, options: Record<string,
|
|
|
64
63
|
/**
|
|
65
64
|
* Dolla's I(nternationalizatio)n module. Manages language translations and locale-based formatting.
|
|
66
65
|
*/
|
|
67
|
-
|
|
66
|
+
declare class I18n {
|
|
68
67
|
#private;
|
|
69
|
-
readonly locale: Signal<string>;
|
|
70
|
-
constructor(
|
|
68
|
+
readonly $locale: Signal<string>;
|
|
69
|
+
constructor();
|
|
71
70
|
get locales(): string[];
|
|
72
|
-
setup(options: I18nSetupOptions): void
|
|
71
|
+
setup(options: I18nSetupOptions): Promise<void>;
|
|
73
72
|
setLocale(name: string): Promise<void>;
|
|
74
73
|
/**
|
|
75
74
|
* Returns a State containing the value at `key`.
|
|
@@ -130,4 +129,6 @@ export declare class I18n {
|
|
|
130
129
|
*/
|
|
131
130
|
list(list: MaybeSignal<Iterable<string>>, options?: Intl.ListFormatOptions): Signal<string>;
|
|
132
131
|
}
|
|
132
|
+
export declare const i18n: I18n;
|
|
133
|
+
export declare const t: (selector: string, options?: TOptions) => Signal<string>;
|
|
133
134
|
export {};
|