@manyducks.co/dolla 2.0.0 → 3.1.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 +133 -284
- package/dist/context-B5blupD2.js +363 -0
- package/dist/context-B5blupD2.js.map +1 -0
- package/dist/core/context.d.ts +29 -144
- package/dist/core/debug.d.ts +19 -0
- package/dist/core/index.d.ts +15 -16
- package/dist/core/markup/helpers.d.ts +34 -0
- package/dist/core/markup/html.d.ts +3 -0
- package/dist/core/{nodes → markup/nodes}/dom.d.ts +5 -4
- package/dist/core/markup/nodes/dynamic.d.ts +16 -0
- package/dist/core/markup/nodes/element.d.ts +14 -0
- package/dist/core/markup/nodes/portal.d.ts +15 -0
- package/dist/core/markup/nodes/repeat.d.ts +21 -0
- package/dist/core/markup/nodes/view.d.ts +17 -0
- package/dist/core/markup/scheduler.d.ts +1 -0
- package/dist/core/markup/types.d.ts +62 -0
- package/dist/core/markup/utils.d.ts +22 -0
- package/dist/core/ref.d.ts +6 -12
- package/dist/core/root.d.ts +36 -0
- package/dist/core/signals.d.ts +46 -76
- package/dist/core/symbols.d.ts +2 -0
- package/dist/core-JHktdqjt.js +242 -0
- package/dist/core-JHktdqjt.js.map +1 -0
- package/dist/http/index.d.ts +21 -33
- package/dist/http.js +89 -149
- package/dist/http.js.map +1 -1
- package/dist/index.js +4 -174
- package/dist/jsx-dev-runtime.d.ts +4 -3
- package/dist/jsx-dev-runtime.js +12 -9
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +5 -4
- package/dist/jsx-runtime.js +17 -12
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/router/index.d.ts +4 -3
- package/dist/router/router.d.ts +19 -162
- package/dist/router/store.d.ts +12 -0
- package/dist/router/types.d.ts +152 -0
- package/dist/router/utils.d.ts +99 -0
- package/dist/router/utils.test.d.ts +1 -0
- package/dist/router.js +428 -5
- package/dist/router.js.map +1 -1
- package/dist/signals-CMJPGr_M.js +354 -0
- package/dist/signals-CMJPGr_M.js.map +1 -0
- package/dist/translate/index.d.ts +82 -0
- package/dist/translate.js +125 -0
- package/dist/translate.js.map +1 -0
- package/dist/types.d.ts +21 -39
- package/dist/utils.d.ts +41 -29
- package/dist/utils.test.d.ts +1 -0
- package/dist/virtual/index.d.ts +1 -0
- package/dist/virtual/list.d.ts +53 -0
- package/package.json +19 -16
- package/dist/core/app.d.ts +0 -24
- package/dist/core/env.d.ts +0 -3
- package/dist/core/hooks.d.ts +0 -70
- package/dist/core/logger.d.ts +0 -42
- package/dist/core/logger.test.d.ts +0 -0
- package/dist/core/markup.d.ts +0 -82
- package/dist/core/markup.test.d.ts +0 -0
- package/dist/core/nodes/_markup.d.ts +0 -36
- package/dist/core/nodes/dynamic.d.ts +0 -22
- package/dist/core/nodes/element.d.ts +0 -27
- package/dist/core/nodes/portal.d.ts +0 -18
- package/dist/core/nodes/repeat.d.ts +0 -27
- package/dist/core/nodes/view.d.ts +0 -25
- package/dist/core/views/default-crash-view.d.ts +0 -25
- package/dist/core/views/for.d.ts +0 -21
- package/dist/core/views/fragment.d.ts +0 -7
- package/dist/core/views/portal.d.ts +0 -16
- package/dist/core/views/show.d.ts +0 -25
- package/dist/fragment-BahD_BJA.js +0 -7
- package/dist/fragment-BahD_BJA.js.map +0 -1
- package/dist/i18n/index.d.ts +0 -134
- package/dist/i18n.js +0 -309
- package/dist/i18n.js.map +0 -1
- package/dist/index-DRJlxs-Q.js +0 -535
- package/dist/index-DRJlxs-Q.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger-Aqi9m1CF.js +0 -565
- package/dist/logger-Aqi9m1CF.js.map +0 -1
- package/dist/markup-8jNhoqDe.js +0 -1089
- package/dist/markup-8jNhoqDe.js.map +0 -1
- package/dist/router/hooks.d.ts +0 -2
- package/dist/router/router.utils.d.ts +0 -93
- package/dist/typeChecking-5kmX0ulW.js +0 -65
- package/dist/typeChecking-5kmX0ulW.js.map +0 -1
- package/dist/typeChecking.d.ts +0 -95
- package/docs/buildless.md +0 -132
- package/docs/components.md +0 -238
- package/docs/hooks.md +0 -356
- package/docs/http.md +0 -178
- package/docs/i18n.md +0 -220
- package/docs/index.md +0 -10
- package/docs/markup.md +0 -136
- package/docs/mixins.md +0 -176
- package/docs/ref.md +0 -77
- package/docs/router.md +0 -281
- package/docs/setup.md +0 -137
- package/docs/signals.md +0 -262
- package/docs/stores.md +0 -113
- package/docs/views.md +0 -356
- package/notes/atomic.md +0 -452
- package/notes/elimination.md +0 -33
- package/notes/observable.md +0 -180
- package/notes/scratch.md +0 -565
- package/notes/splitting.md +0 -5
- package/notes/views.md +0 -195
- package/vite.config.js +0 -22
- /package/dist/core/{hooks.test.d.ts → markup/html.test.d.ts} +0 -0
- /package/dist/core/{ref.test.d.ts → markup/utils.test.d.ts} +0 -0
- /package/dist/router/{router.utils.test.d.ts → matcher.test.d.ts} +0 -0
- /package/dist/{typeChecking.test.d.ts → router/router.test.d.ts} +0 -0
package/dist/core/index.d.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export {
|
|
1
|
+
export { createRoot } from "./root.js";
|
|
2
|
+
export type { DollaPlugin } from "./root.js";
|
|
3
|
+
export { batch, compose, createAtom, createEffect, peek, subscribe, unwrap } from "./signals.js";
|
|
4
|
+
export type { Getter, Setter } from "./signals.js";
|
|
5
|
+
export { addStore, getNearestViewNode, getRootElement, getStore, onCleanup, onEffect, onMount } from "./context.js";
|
|
6
6
|
export type { Context } from "./context.js";
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export type {
|
|
16
|
-
export type { CSSProperties, Env, InputType, Mixin, Renderable, Store, View } from "../types.js";
|
|
17
|
-
export type { CrashViewProps } from "./views/default-crash-view.js";
|
|
7
|
+
export { createDebug, getDebug, setLogFilter, setLogLevel } from "./debug.js";
|
|
8
|
+
export { createPortal, forEach, hideIf, showIf } from "./markup/helpers.js";
|
|
9
|
+
export { html } from "./markup/html.js";
|
|
10
|
+
export { ViewNode } from "./markup/nodes/view.js";
|
|
11
|
+
export type { Markup, MarkupNode } from "./markup/types.js";
|
|
12
|
+
export { createMarkup, render } from "./markup/utils.js";
|
|
13
|
+
export { createRef } from "./ref.js";
|
|
14
|
+
export type { Ref } from "./ref.js";
|
|
15
|
+
export type { CSSProperties, Env, InputType, MaybeGetter, Renderable, Store, View } from "../types.js";
|
|
18
16
|
import type { IntrinsicElements as Elements } from "../types.js";
|
|
19
17
|
declare global {
|
|
20
18
|
namespace JSX {
|
|
21
19
|
interface IntrinsicElements extends Elements {
|
|
20
|
+
[tag: `${string}-${string}`]: any;
|
|
22
21
|
[tag: string]: any;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Renderable } from "..";
|
|
2
|
+
import { type Getter } from "../signals";
|
|
3
|
+
import { PortalNode } from "./nodes/portal";
|
|
4
|
+
import { KeyFn, RenderFn } from "./nodes/repeat";
|
|
5
|
+
/**
|
|
6
|
+
* Displays a dynamic list. Items will be added and removed as the list is updated.
|
|
7
|
+
*
|
|
8
|
+
* @param items - List items. Can be reactive.
|
|
9
|
+
* @param keyFn - Takes (item, index) as plain values and returns a unique key to identify that item (usually the item's ID).
|
|
10
|
+
* @param renderFn - Takes (item, index) as Reactive values and returns content to display for that item.
|
|
11
|
+
*/
|
|
12
|
+
export declare function forEach<T>(items: Getter<Iterable<T>> | Iterable<T>, keyFn: KeyFn<T>, renderFn: RenderFn<T>): Renderable;
|
|
13
|
+
/**
|
|
14
|
+
* Shows content only when `condition` is truthy.
|
|
15
|
+
* It can be a plain value or a Getter to track dynamically.
|
|
16
|
+
*
|
|
17
|
+
* @param condition - Condition to hide or show content on.
|
|
18
|
+
* @param content - Content to display when condition is truthy.
|
|
19
|
+
* @param fallback - Content to display when condition is falsy.
|
|
20
|
+
*/
|
|
21
|
+
export declare function showIf(condition: any, content: Renderable, fallback?: Renderable): Renderable;
|
|
22
|
+
/**
|
|
23
|
+
* Shows content only when `condition` is falsy.
|
|
24
|
+
* It can be a plain value or a Getter to track dynamically.
|
|
25
|
+
*
|
|
26
|
+
* @param condition - Condition to hide or show content on.
|
|
27
|
+
* @param content - Content to display when condition is falsy.
|
|
28
|
+
* @param fallback - Content to display when condition is truthy.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hideIf(condition: any, content: Renderable, fallback?: Renderable): Renderable;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a portal that renders `content` into another element on the page.
|
|
33
|
+
**/
|
|
34
|
+
export declare function createPortal(parent: Element, content: Renderable): import("./types").Markup<typeof PortalNode>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { MarkupNode, type MountTarget } from "../types.js";
|
|
2
3
|
/**
|
|
3
4
|
* A lightweight MarkupNode wrapper for a plain DOM node.
|
|
4
5
|
*/
|
|
5
6
|
export declare class DOMNode extends MarkupNode {
|
|
6
|
-
private
|
|
7
|
-
constructor(node: Node);
|
|
7
|
+
#private;
|
|
8
|
+
constructor(_context: Context, node: Node);
|
|
8
9
|
getRoot(): Node;
|
|
9
10
|
isMounted(): boolean;
|
|
10
|
-
mount(parent:
|
|
11
|
+
mount(parent: MountTarget, after?: Node): void;
|
|
11
12
|
unmount(skipDOM?: boolean): void;
|
|
12
13
|
move(parent: Element, after?: Node): void;
|
|
13
14
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Context } from "../../context.js";
|
|
2
|
+
import { type Getter } from "../../signals.js";
|
|
3
|
+
import { MarkupNode, MountTarget } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders any kind of content; markup, signals, DOM nodes, etc.
|
|
6
|
+
* If it can be rendered by Dolla then Dynamic will do it.
|
|
7
|
+
*/
|
|
8
|
+
export declare class DynamicNode extends MarkupNode {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(context: Context, slot: Getter<any>);
|
|
11
|
+
getRoot(): Text;
|
|
12
|
+
isMounted(): boolean;
|
|
13
|
+
mount(parent: MountTarget, after?: Node): void;
|
|
14
|
+
unmount(skipDOM?: boolean): void;
|
|
15
|
+
move(parent: MountTarget, after?: Node): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Context } from "../../context.js";
|
|
2
|
+
import { MarkupNode, MountTarget } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders an HTML or SVG element.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ElementNode extends MarkupNode {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(context: Context, tag: string, props: Record<string, any>);
|
|
9
|
+
getRoot(): HTMLElement | SVGElement;
|
|
10
|
+
isMounted(): boolean;
|
|
11
|
+
mount(parent: MountTarget, after?: Node): void;
|
|
12
|
+
unmount(skipDOM?: boolean): void;
|
|
13
|
+
move(parent: MountTarget, after?: Node): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Renderable } from "../../../types.js";
|
|
2
|
+
import { Context } from "../../context.js";
|
|
3
|
+
import { MarkupNode, MountTarget } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders content into a specified parent node.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PortalNode extends MarkupNode {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(context: Context, value: Renderable, parent: MountTarget);
|
|
10
|
+
getRoot(): Text;
|
|
11
|
+
isMounted(): boolean;
|
|
12
|
+
mount(logicalParent: MountTarget, after?: Node): void;
|
|
13
|
+
unmount(skipDOM?: boolean): void;
|
|
14
|
+
move(logicalParent: MountTarget, after?: Node): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Renderable } from "../../../types.js";
|
|
2
|
+
import type { Context } from "../../context.js";
|
|
3
|
+
import { type Getter } from "../../signals.js";
|
|
4
|
+
import { MarkupNode } from "../types.js";
|
|
5
|
+
export type Key = any;
|
|
6
|
+
export type KeyFn<T> = (item: T, index: number) => Key;
|
|
7
|
+
export type RenderFn<T> = (item: Getter<T>, index: Getter<number>) => Renderable;
|
|
8
|
+
/**
|
|
9
|
+
* Renders a list of items.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RepeatNode<T> extends MarkupNode {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(context: Context, items: Getter<Iterable<T>>, key: KeyFn<T>, render: RenderFn<T>);
|
|
14
|
+
getRoot(): Text;
|
|
15
|
+
isMounted(): boolean;
|
|
16
|
+
mount(parent: Element, after?: Node): void;
|
|
17
|
+
unmount(skipDOM?: boolean): void;
|
|
18
|
+
move(parent: Element, after?: Node): void;
|
|
19
|
+
private _cleanup;
|
|
20
|
+
private _update;
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { View } from "../../../types.js";
|
|
2
|
+
import { ComponentState, Context } from "../../context.js";
|
|
3
|
+
import { MarkupNode } from "../types.js";
|
|
4
|
+
export declare const VIEW: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Renders a View.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ViewNode<P> extends MarkupNode {
|
|
9
|
+
#private;
|
|
10
|
+
readonly context: Context<ComponentState & Record<string | symbol, any>>;
|
|
11
|
+
constructor(context: Context, view: View<P>, props: P);
|
|
12
|
+
getRoot(): Node | undefined;
|
|
13
|
+
isMounted(): boolean;
|
|
14
|
+
mount(parent: Element, after?: Node): void;
|
|
15
|
+
unmount(skipDOM?: boolean): void;
|
|
16
|
+
move(parent: Element, after?: Node): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function scheduleUpdate(updateFn: () => void): void;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IntrinsicElements, View } from "../../types.js";
|
|
2
|
+
import { Context } from "../index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Determines the type of the `props` object for any kind of Markup type.
|
|
5
|
+
*/
|
|
6
|
+
export type PropsOf<T extends string | View<any> | (new (...args: any[]) => MarkupNode)> = T extends View<infer P> ? P : T extends new (...args: infer Args) => MarkupNode ? {
|
|
7
|
+
args: Args extends [Context, ...infer Rest] ? Rest : [];
|
|
8
|
+
} : T extends keyof IntrinsicElements ? IntrinsicElements[T] : any;
|
|
9
|
+
export declare const IS_MARKUP: unique symbol;
|
|
10
|
+
export declare const IS_MARKUP_NODE: unique symbol;
|
|
11
|
+
export declare const IS_MARKUP_NODE_CLASS: unique symbol;
|
|
12
|
+
/**
|
|
13
|
+
* A set of basic metadata that can be constructed into a `MarkupNode`.
|
|
14
|
+
*/
|
|
15
|
+
export interface Markup<Type extends string | View<any> | (new (...args: any[]) => MarkupNode) = string | View<any> | (new (...args: any[]) => MarkupNode)> {
|
|
16
|
+
[IS_MARKUP]: true;
|
|
17
|
+
type: Type;
|
|
18
|
+
props: PropsOf<Type>;
|
|
19
|
+
}
|
|
20
|
+
export interface MountTarget {
|
|
21
|
+
insertBefore(node: Node, child: Node | null): any;
|
|
22
|
+
moveBefore?: (node: Node, child: Node | null) => any;
|
|
23
|
+
appendChild(node: Node): any;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A node that can be mounted by the Markup layout engine. Can be extended to create new custom node types.
|
|
27
|
+
*
|
|
28
|
+
* A `MarkupNode` instance can be passed anywhere a `Renderable` is required.
|
|
29
|
+
*/
|
|
30
|
+
export declare abstract class MarkupNode {
|
|
31
|
+
static [IS_MARKUP_NODE_CLASS]: boolean;
|
|
32
|
+
get [IS_MARKUP_NODE](): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Returns a single DOM node to represent this MarkupNode's position in the DOM.
|
|
35
|
+
* Usually the parent element, but it can be an empty Text node used as a marker.
|
|
36
|
+
*
|
|
37
|
+
* It only needs to be defined while the node is mounted, so it can be created in the `mount` function.
|
|
38
|
+
*/
|
|
39
|
+
abstract getRoot(): Node | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Returns true while this node is mounted.
|
|
42
|
+
*/
|
|
43
|
+
abstract isMounted(): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Mount this node to a `parent` element.
|
|
46
|
+
* If passed, this node will be mounted as the next sibling of `after`.
|
|
47
|
+
*/
|
|
48
|
+
abstract mount(parent: MountTarget, after?: Node): void;
|
|
49
|
+
/**
|
|
50
|
+
* Unmount this MarkupNode from its parent element.
|
|
51
|
+
*
|
|
52
|
+
* The `skipDOM` option can be passed as an optimization when unmounting a parent node.
|
|
53
|
+
* A value of `true` indicates that no DOM operations need to happen because the parent is already being unmounted.
|
|
54
|
+
*
|
|
55
|
+
* @param skipDOM - No DOM updates will be performed when true. Lifecycle methods will be called regardless.
|
|
56
|
+
*/
|
|
57
|
+
abstract unmount(skipDOM?: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* Moves a node without unmounting and remounting (if the browser supports Element.moveBefore).
|
|
60
|
+
*/
|
|
61
|
+
abstract move(parent: MountTarget, after?: Node): void;
|
|
62
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Renderable, View } from "../../types.js";
|
|
2
|
+
import { Context } from "../context.js";
|
|
3
|
+
import { Markup, MarkupNode, MountTarget, PropsOf } from "./types.js";
|
|
4
|
+
export declare function createMarkup<Type extends string | View<any> | (new (...args: any[]) => MarkupNode)>(type: Type, props: PropsOf<Type>): Markup<Type>;
|
|
5
|
+
export declare function isMarkup<T extends string | View<any> | (new (...args: any[]) => MarkupNode)>(value: any): value is Markup<T>;
|
|
6
|
+
export declare function isMarkupNode(value: any): value is MarkupNode;
|
|
7
|
+
export declare function isMarkupNodeClass(value: any): value is new (...args: any[]) => MarkupNode;
|
|
8
|
+
/**
|
|
9
|
+
* Takes any `Renderable` value and returns a `MarkupNode` that will display it.
|
|
10
|
+
*/
|
|
11
|
+
export declare function render(content: Renderable, context?: Context<Record<string | symbol, any>>): MarkupNode;
|
|
12
|
+
/**
|
|
13
|
+
* Convert basically anything into an array of `MarkupNode`
|
|
14
|
+
*/
|
|
15
|
+
export declare function toMarkupNodes(context: Context, ...content: any[]): MarkupNode[];
|
|
16
|
+
export declare function addChild(parent: MountTarget, node: Node, after?: Node | null): void;
|
|
17
|
+
export declare function createTextNode(text: string): Text;
|
|
18
|
+
/**
|
|
19
|
+
* Moves an element using `moveBefore` if the browser supports it, otherwise falls back to `insertBefore`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function moveAfter(parent: MountTarget, node: Node, after?: Node | null): void;
|
|
22
|
+
export declare function addListener<T extends Event>(target: EventTarget, event: string, listener: (event: T) => any): () => void;
|
package/dist/core/ref.d.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
export declare const EMPTY_REF: unique symbol;
|
|
2
|
-
/**
|
|
3
|
-
* A hybrid getter/setter function that stores the last value it was called with.
|
|
4
|
-
* Guarantees a value is held at runtime by throwing an error if no value is set.
|
|
5
|
-
*/
|
|
6
1
|
export interface Ref<T> {
|
|
7
2
|
/**
|
|
8
|
-
*
|
|
3
|
+
* Call with no arguments to get the stored value.
|
|
4
|
+
* Throws an error if the ref is empty (this means you forgot to pass it or it was called after teardown).
|
|
9
5
|
*/
|
|
10
6
|
(): T;
|
|
11
7
|
/**
|
|
12
|
-
*
|
|
8
|
+
* Call with an argument to initialize the value. Returns a cleanup function.
|
|
9
|
+
* The cleanup function should clear any references to the DOM node.
|
|
13
10
|
*/
|
|
14
|
-
(value: T):
|
|
11
|
+
(value: T): () => void;
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
* Creates a Ref.
|
|
18
|
-
*/
|
|
19
|
-
export declare function ref<T>(value?: T): Ref<T>;
|
|
13
|
+
export declare function createRef<T = HTMLElement>(): Ref<T>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Renderable, View } from "../types.js";
|
|
2
|
+
import { type Context } from "./context.js";
|
|
3
|
+
export type CleanupCallback = () => void | Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Plugins run before the app is mounted. If they return a promise, mounting will be delayed until the promise resolves.
|
|
6
|
+
* If a cleanup function is returned, it will be called before the app is unmounted. The cleanup function's promise will delay unmounting.
|
|
7
|
+
*
|
|
8
|
+
* Hooks can be used inside plugins.
|
|
9
|
+
*/
|
|
10
|
+
export type DollaPlugin = (context: Context) => Promise<CleanupCallback | void> | CleanupCallback | void;
|
|
11
|
+
export interface DollaRootOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Adds additional view info to the DOM to help with debugging.
|
|
14
|
+
*/
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface DollaRoot {
|
|
18
|
+
/**
|
|
19
|
+
* Registers a plugin to be added before `mount`.
|
|
20
|
+
*/
|
|
21
|
+
plugin(plugin: DollaPlugin): DollaRoot;
|
|
22
|
+
/**
|
|
23
|
+
* Mounts a `view` to this root.
|
|
24
|
+
*/
|
|
25
|
+
mount(view: View<{}>): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Mounts any renderable content to this root.
|
|
28
|
+
*/
|
|
29
|
+
mount(content: Renderable): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Unmounts the currently mounted content.
|
|
32
|
+
*/
|
|
33
|
+
unmount(): void;
|
|
34
|
+
}
|
|
35
|
+
export declare function createRoot(selector: string, options?: DollaRootOptions): DollaRoot;
|
|
36
|
+
export declare function createRoot(element: Element, options?: DollaRootOptions): DollaRoot;
|
package/dist/core/signals.d.ts
CHANGED
|
@@ -1,100 +1,70 @@
|
|
|
1
|
-
import { Context } from "./context";
|
|
2
|
-
export declare function getCurrentContext(): Context | undefined;
|
|
3
|
-
export declare function setCurrentContext(context: Context | undefined): Context | undefined;
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Automatically tracked as a dependency when called within a tracking scope (such as `memo` or `effect` functions).
|
|
2
|
+
* Returns the currently held value. Registers the state as a dependency when called within a tracking context.
|
|
7
3
|
*/
|
|
8
|
-
export
|
|
9
|
-
(): T;
|
|
10
|
-
}
|
|
4
|
+
export type Getter<T> = () => T;
|
|
11
5
|
/**
|
|
12
|
-
* A
|
|
6
|
+
* A value that may be a static value or a getter function.
|
|
7
|
+
* Can be converted to a plain value with `unwrap`.
|
|
13
8
|
*/
|
|
14
|
-
export
|
|
15
|
-
(value: T | ((previousValue: T) => T)): void;
|
|
16
|
-
}
|
|
9
|
+
export type MaybeGetter<T> = T | Getter<T>;
|
|
17
10
|
/**
|
|
18
|
-
*
|
|
11
|
+
* Updates the value of an atom. Takes a new plain value, or an update function to compute one.
|
|
19
12
|
*/
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
}
|
|
13
|
+
export type Setter<T> = (next: SetterAction<T>) => T;
|
|
14
|
+
export type SetterAction<T> = T | ((prev: T) => T);
|
|
23
15
|
/**
|
|
24
|
-
*
|
|
25
|
-
* This value can be unwrapped to a plain value with `get` or `untracked` (depending on whether you're in a tracking context and need to track it).
|
|
16
|
+
* A getter and setter pair, as returned from `createAtom`.
|
|
26
17
|
*/
|
|
27
|
-
export type
|
|
28
|
-
export type EqualityFn<T> = (previousValue: T, nextValue: T) => boolean;
|
|
29
|
-
export interface SignalOptions<T> {
|
|
30
|
-
/**
|
|
31
|
-
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
32
|
-
*/
|
|
33
|
-
equals?: EqualityFn<T>;
|
|
34
|
-
}
|
|
35
|
-
export declare function writable<T>(): Writable<T | undefined>;
|
|
36
|
-
export declare function writable<T>(initialValue: undefined, options: SignalOptions<T | undefined>): Writable<T | undefined>;
|
|
37
|
-
export declare function writable<T>(initialValue: T, options?: SignalOptions<T>): Writable<T>;
|
|
18
|
+
export type AtomAccessors<T> = [Getter<T>, Setter<T>];
|
|
38
19
|
/**
|
|
39
|
-
*
|
|
20
|
+
* Creates a new atom with a default `undefined` value.
|
|
21
|
+
* Returns a `[getter, setter]` function tuple.
|
|
40
22
|
*
|
|
41
23
|
* @example
|
|
42
|
-
* const
|
|
43
|
-
*
|
|
44
|
-
* const $number = writable(5);
|
|
45
|
-
* const $value = readable($number);
|
|
46
|
-
* $number(); // 5
|
|
47
|
-
* $value(); // 5
|
|
48
|
-
* $number.set(6);
|
|
49
|
-
* $number(); // 6
|
|
50
|
-
* $value(); // 6 (tracks value but can't be written)
|
|
24
|
+
* const [getValue, setValue] = createAtom();
|
|
51
25
|
*/
|
|
52
|
-
export declare function
|
|
26
|
+
export declare function createAtom<T>(): AtomAccessors<T | undefined>;
|
|
53
27
|
/**
|
|
54
|
-
* Creates a new
|
|
28
|
+
* Creates a new atom with a value computed from an existing getter.
|
|
29
|
+
* This is usually used to create a 'settable' getter, in which you can store
|
|
30
|
+
* a temporary value until it gets overwritten by a _real_ update.
|
|
55
31
|
*
|
|
56
32
|
* @example
|
|
57
|
-
* const [
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
deps?: Signal<any>[];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Creates a derived signal that recomputes its value only when its dependencies change.
|
|
71
|
-
* Subsequent calls will return a cached value.
|
|
72
|
-
* Dependencies are tracked when called inside `fn` by default,
|
|
73
|
-
* but can be overridden by passing a `deps` array in the options object.
|
|
74
|
-
*/
|
|
75
|
-
export declare function memo<T>(compute: (previousValue?: T) => MaybeSignal<T>, options?: MemoOptions<T>): Signal<T>;
|
|
76
|
-
/**
|
|
77
|
-
* Suspends effects during `fn`. Effects for all updated Signal values are called at the end of the batch.
|
|
33
|
+
* const [getValue, setValue] = createAtom("");
|
|
34
|
+
* const [getInputValue, setInputValue] = createAtom(getValue);
|
|
35
|
+
*
|
|
36
|
+
* setInputValue("temporary");
|
|
37
|
+
* getValue("");
|
|
38
|
+
* getInputValue(); // "temporary"
|
|
39
|
+
*
|
|
40
|
+
* setValue("overwritten");
|
|
41
|
+
* getValue("overwritten");
|
|
42
|
+
* getInputValue(); // "overwritten"
|
|
78
43
|
*/
|
|
79
|
-
export declare function
|
|
44
|
+
export declare function createAtom<T>(compute: Getter<T>): AtomAccessors<T>;
|
|
80
45
|
/**
|
|
81
|
-
*
|
|
46
|
+
* Creates a new atom with an initial value.
|
|
47
|
+
* Returns a `[getter, setter]` function tuple.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const [getCount, setCount] = createAtom(5);
|
|
82
51
|
*/
|
|
83
|
-
export declare function
|
|
52
|
+
export declare function createAtom<T>(initialValue: T): AtomAccessors<T>;
|
|
53
|
+
export declare function compose<T>(getter: (previousValue?: T) => Getter<T> | T): Getter<T>;
|
|
54
|
+
export declare function createEffect(fn: () => void): () => void;
|
|
84
55
|
/**
|
|
85
|
-
* Unwraps
|
|
56
|
+
* Unwraps a `MaybeGetter<T>` into a plain `T`.
|
|
57
|
+
* Tracks the value if it is a getter.
|
|
58
|
+
* Use the non-tracking `peek` if you're being stealthy.
|
|
86
59
|
*/
|
|
87
|
-
export declare function
|
|
60
|
+
export declare function unwrap<T>(value: T | Getter<T>): T;
|
|
88
61
|
/**
|
|
89
|
-
*
|
|
62
|
+
* Unwraps a `MaybeGetter<T>` into a plain `T`. Will _not_ track if the value is a getter.
|
|
90
63
|
*/
|
|
91
|
-
export
|
|
92
|
-
export type UnsubscribeFn = () => void;
|
|
64
|
+
export declare function peek<T>(value: T | Getter<T>): T;
|
|
93
65
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* NOTE: You must call the unsubscribe function to clean up the effect.
|
|
98
|
-
* If you are using an effect inside a View or Store, try the `useEffect` hook instead, which cleans up automatically when the component unmounts.
|
|
66
|
+
* Groups several signal changes into a single transaction.
|
|
67
|
+
* Suspends effects until `callback` finishes, then runs all updates at once.
|
|
99
68
|
*/
|
|
100
|
-
export declare function
|
|
69
|
+
export declare function batch(callback: () => void): void;
|
|
70
|
+
export declare function subscribe<T>(target: Getter<T>, fn: (value: T) => any): () => void;
|