@manyducks.co/dolla 2.0.0 → 3.0.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.
Files changed (112) hide show
  1. package/README.md +133 -284
  2. package/dist/core/context.d.ts +22 -146
  3. package/dist/core/debug.d.ts +19 -0
  4. package/dist/core/index.d.ts +15 -16
  5. package/dist/core/markup/helpers.d.ts +34 -0
  6. package/dist/core/markup/html.d.ts +3 -0
  7. package/dist/core/{nodes → markup/nodes}/dom.d.ts +5 -4
  8. package/dist/core/markup/nodes/dynamic.d.ts +16 -0
  9. package/dist/core/markup/nodes/element.d.ts +14 -0
  10. package/dist/core/markup/nodes/portal.d.ts +15 -0
  11. package/dist/core/markup/nodes/repeat.d.ts +21 -0
  12. package/dist/core/markup/nodes/view.d.ts +17 -0
  13. package/dist/core/markup/scheduler.d.ts +1 -0
  14. package/dist/core/markup/types.d.ts +62 -0
  15. package/dist/core/markup/utils.d.ts +22 -0
  16. package/dist/core/ref.d.ts +6 -12
  17. package/dist/core/root.d.ts +36 -0
  18. package/dist/core/signals.d.ts +46 -76
  19. package/dist/core/symbols.d.ts +2 -0
  20. package/dist/core-BLkJ-xuh.js +242 -0
  21. package/dist/core-BLkJ-xuh.js.map +1 -0
  22. package/dist/http/index.d.ts +21 -33
  23. package/dist/http.js +89 -149
  24. package/dist/http.js.map +1 -1
  25. package/dist/index.js +4 -174
  26. package/dist/jsx-dev-runtime.d.ts +4 -3
  27. package/dist/jsx-dev-runtime.js +12 -9
  28. package/dist/jsx-dev-runtime.js.map +1 -1
  29. package/dist/jsx-runtime.d.ts +5 -4
  30. package/dist/jsx-runtime.js +17 -12
  31. package/dist/jsx-runtime.js.map +1 -1
  32. package/dist/router/index.d.ts +4 -3
  33. package/dist/router/router.d.ts +19 -162
  34. package/dist/router/store.d.ts +12 -0
  35. package/dist/router/types.d.ts +152 -0
  36. package/dist/router/utils.d.ts +99 -0
  37. package/dist/router/utils.test.d.ts +1 -0
  38. package/dist/router.js +428 -5
  39. package/dist/router.js.map +1 -1
  40. package/dist/signals-CMJPGr_M.js +354 -0
  41. package/dist/signals-CMJPGr_M.js.map +1 -0
  42. package/dist/translate/index.d.ts +82 -0
  43. package/dist/translate.js +125 -0
  44. package/dist/translate.js.map +1 -0
  45. package/dist/types.d.ts +21 -39
  46. package/dist/utils.d.ts +41 -29
  47. package/dist/utils.test.d.ts +1 -0
  48. package/dist/view-cBN-hn_T.js +360 -0
  49. package/dist/view-cBN-hn_T.js.map +1 -0
  50. package/dist/virtual/index.d.ts +1 -0
  51. package/dist/virtual/list.d.ts +53 -0
  52. package/package.json +19 -16
  53. package/dist/core/app.d.ts +0 -24
  54. package/dist/core/env.d.ts +0 -3
  55. package/dist/core/hooks.d.ts +0 -70
  56. package/dist/core/logger.d.ts +0 -42
  57. package/dist/core/logger.test.d.ts +0 -0
  58. package/dist/core/markup.d.ts +0 -82
  59. package/dist/core/markup.test.d.ts +0 -0
  60. package/dist/core/nodes/_markup.d.ts +0 -36
  61. package/dist/core/nodes/dynamic.d.ts +0 -22
  62. package/dist/core/nodes/element.d.ts +0 -27
  63. package/dist/core/nodes/portal.d.ts +0 -18
  64. package/dist/core/nodes/repeat.d.ts +0 -27
  65. package/dist/core/nodes/view.d.ts +0 -25
  66. package/dist/core/views/default-crash-view.d.ts +0 -25
  67. package/dist/core/views/for.d.ts +0 -21
  68. package/dist/core/views/fragment.d.ts +0 -7
  69. package/dist/core/views/portal.d.ts +0 -16
  70. package/dist/core/views/show.d.ts +0 -25
  71. package/dist/fragment-BahD_BJA.js +0 -7
  72. package/dist/fragment-BahD_BJA.js.map +0 -1
  73. package/dist/i18n/index.d.ts +0 -134
  74. package/dist/i18n.js +0 -309
  75. package/dist/i18n.js.map +0 -1
  76. package/dist/index-DRJlxs-Q.js +0 -535
  77. package/dist/index-DRJlxs-Q.js.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. package/dist/logger-Aqi9m1CF.js +0 -565
  80. package/dist/logger-Aqi9m1CF.js.map +0 -1
  81. package/dist/markup-8jNhoqDe.js +0 -1089
  82. package/dist/markup-8jNhoqDe.js.map +0 -1
  83. package/dist/router/hooks.d.ts +0 -2
  84. package/dist/router/router.utils.d.ts +0 -93
  85. package/dist/typeChecking-5kmX0ulW.js +0 -65
  86. package/dist/typeChecking-5kmX0ulW.js.map +0 -1
  87. package/dist/typeChecking.d.ts +0 -95
  88. package/docs/buildless.md +0 -132
  89. package/docs/components.md +0 -238
  90. package/docs/hooks.md +0 -356
  91. package/docs/http.md +0 -178
  92. package/docs/i18n.md +0 -220
  93. package/docs/index.md +0 -10
  94. package/docs/markup.md +0 -136
  95. package/docs/mixins.md +0 -176
  96. package/docs/ref.md +0 -77
  97. package/docs/router.md +0 -281
  98. package/docs/setup.md +0 -137
  99. package/docs/signals.md +0 -262
  100. package/docs/stores.md +0 -113
  101. package/docs/views.md +0 -356
  102. package/notes/atomic.md +0 -452
  103. package/notes/elimination.md +0 -33
  104. package/notes/observable.md +0 -180
  105. package/notes/scratch.md +0 -565
  106. package/notes/splitting.md +0 -5
  107. package/notes/views.md +0 -195
  108. package/vite.config.js +0 -22
  109. /package/dist/core/{hooks.test.d.ts → markup/html.test.d.ts} +0 -0
  110. /package/dist/core/{ref.test.d.ts → markup/utils.test.d.ts} +0 -0
  111. /package/dist/router/{router.utils.test.d.ts → matcher.test.d.ts} +0 -0
  112. /package/dist/{typeChecking.test.d.ts → router/router.test.d.ts} +0 -0
@@ -1,147 +1,23 @@
1
- import type { Store } from "../types";
2
- import { type Logger, type LoggerOptions } from "./logger";
3
- import { type EffectFn, type MaybeSignal, type UnsubscribeFn } from "./signals";
4
- export declare enum LifecycleEvent {
5
- WILL_MOUNT = "willMount",
6
- DID_MOUNT = "didMount",
7
- WILL_UNMOUNT = "willUnmount",
8
- DID_UNMOUNT = "didUnmount",
9
- DISPOSE = "dispose"
10
- }
11
- export type LifecycleEventName = "willMount" | "didMount" | "willUnmount" | "didUnmount" | "dispose";
12
- type LifecycleListener = () => void;
13
- declare enum LifecycleState {
14
- Unmounted = 0,
15
- WillMount = 1,
16
- DidMount = 2,
17
- WillUnmount = 3,
18
- DidUnmount = 4,
19
- Disposed = 5
20
- }
21
- declare const NAME: unique symbol;
22
- declare const LIFECYCLE: unique symbol;
23
- declare const PARENT: unique symbol;
24
- declare const STORES: unique symbol;
25
- declare const STATE: unique symbol;
26
- /**
27
- * Manages lifecycle events for a Context.
28
- */
29
- declare class ContextLifecycle {
30
- private context;
31
- state: LifecycleState;
32
- listeners: Map<LifecycleEvent, Set<LifecycleListener>>;
33
- bound?: Set<Context>;
34
- constructor(context: Context);
35
- /**
36
- * Listen for a certain event to be emitted. Listeners are called when the event results in a state change.
37
- */
38
- on<E extends LifecycleEvent>(event: E, listener: LifecycleListener): void;
39
- /**
40
- * Stop a particular listener from being called when an event is emitted.
41
- */
42
- off<E extends LifecycleEvent>(event: E, listener: LifecycleListener): void;
43
- /**
44
- * Advance the lifecycle state machine.
45
- */
46
- emit<E extends LifecycleEvent>(event: E): void;
47
- /**
48
- * Bind `context` to this lifecycle; when any event is emitted here it will be emitted for `context` as well.
49
- */
50
- bind(context: Context): void;
51
- /**
52
- * Call all the event's listeners and re-emit to bound contexts.
53
- */
54
- private notify;
55
- }
56
- export interface ContextGetStateOptions<T> {
57
- fallback?: T;
58
- /**
59
- * Only check this context; skip parent contexts.
60
- */
61
- immediate?: boolean;
62
- }
63
- export interface ContextGetStateOptionsWithFallbackValue<T> extends ContextGetStateOptions<T> {
64
- fallback: T;
65
- }
66
- export interface ContextGetStateMapOptions {
67
- /**
68
- * Only include state from this context; skip parent contexts.
69
- */
70
- immediate?: boolean;
71
- }
72
- export interface ContextOptions {
73
- logger?: LoggerOptions;
74
- }
75
- export interface LinkedContextOptions extends ContextOptions {
76
- bindLifecycleToParent?: boolean;
77
- }
78
- export interface Context extends Logger {
79
- }
80
- export declare class Context implements Logger {
81
- #private;
82
- [NAME]: string;
83
- [LIFECYCLE]: ContextLifecycle;
84
- [PARENT]?: Context;
85
- [STORES]?: Map<Store<any, any>, any>;
86
- [STATE]?: Map<any, any>;
87
- get isMounted(): boolean;
88
- /**
89
- * Returns a new Context with this one as its parent.
90
- */
91
- static createChildOf(parent: Context, name: MaybeSignal<string>, options?: LinkedContextOptions): Context;
92
- /**
93
- * Emit a lifecycle event to `context`.
94
- */
95
- static emit(context: Context, event: LifecycleEvent): void;
96
- constructor(name: MaybeSignal<string>, options?: ContextOptions);
97
- /**
98
- * Returns the current name of this context.
99
- */
100
- getName(): string;
101
- /**
102
- * Sets a new name for this context.
103
- */
104
- setName(name: MaybeSignal<string>): void;
105
- /**
106
- * Creates an instance of a store and attaches it to this context.
107
- */
108
- provideStore<T>(store: Store<any, T>, options?: any): this;
109
- /**
110
- * Retrieves the nearest instance of `store`. If this context doesn't have it, the parent context is checked. This process continues until either:
111
- * 1. An instance of the store is found and returned.
112
- * 2. No instance is found and an error is thrown.
113
- */
114
- useStore<T>(store: Store<any, T>): T;
115
- /**
116
- * Registers a `listener` to be called at a specific transition point during this context's lifecycle.
117
- *
118
- * Prefer `useMount` and `useUnmount` hooks for general usage.
119
- */
120
- onLifecycleTransition(event: LifecycleEventName, listener: LifecycleListener): () => void;
121
- effect(callback: EffectFn): UnsubscribeFn;
122
- /**
123
- * Gets the value stored at `key`, or returns `options.fallback` if none is set.
124
- */
125
- getState<T>(key: any, options: ContextGetStateOptionsWithFallbackValue<T>): T;
126
- /**
127
- * Gets the value stored at `key`, or throws an error if none is set.
128
- */
129
- getState<T>(key: any, options?: ContextGetStateOptions<T>): T;
130
- /**
131
- * Returns a Map containing all state values available to this context.
132
- *
133
- * Pass `options.immediate` to only include state stored on this context.
134
- * By default all state stored on parent contexts is also included.
135
- */
136
- getStateMap(options?: ContextGetStateMapOptions): Map<any, any>;
137
- /**
138
- * Stores `value` at `key` in this context's state.
139
- */
140
- setState<T>(key: any, value: T): void;
141
- /**
142
- * For each tuple in `entries`, stores `value` at `key` in this context's state.
143
- */
144
- setState(entries: [key: any, value: any][]): void;
145
- }
146
- export declare function createContext(name: MaybeSignal<string>, options?: ContextOptions): Context;
1
+ import type { Store } from "../types.js";
2
+ export type LifecycleListener = () => any;
3
+ type ContextState = {
4
+ isMounted: boolean;
5
+ };
6
+ export type ComponentState = ContextState & {
7
+ name: string;
8
+ };
9
+ export type Context<T = Record<string | symbol, any>> = ContextState & T;
10
+ export declare function createContext(parent?: Context): Context;
11
+ export declare function mountContext(context: Context): void;
12
+ export declare function unmountContext(context: Context): void;
13
+ export declare function onMount(context: Context, fn: LifecycleListener): void;
14
+ export declare function onCleanup(context: Context, fn: LifecycleListener): void;
15
+ export declare function onEffect(context: Context, fn: () => void): void;
16
+ export declare const STORE_ID: unique symbol;
17
+ export declare function addStore<Props, Returns>(context: Context, store: Store<Props, Returns> & {
18
+ [STORE_ID]?: symbol;
19
+ }, ...args: undefined extends Props ? [props?: Props] : [props: Props]): Returns;
20
+ export declare function getStore<Returns>(context: Context, store: Store<any, Returns> & {
21
+ [STORE_ID]?: symbol;
22
+ }): Returns;
147
23
  export {};
@@ -0,0 +1,19 @@
1
+ import { Context } from "./context.js";
2
+ export declare const noOp: () => void;
3
+ export type LogLevel = "info" | "log" | "warn" | "error" | "silent";
4
+ export declare const setLogLevel: (level: LogLevel) => void;
5
+ export declare const setLogFilter: (filter: (name: string) => boolean) => void;
6
+ export declare function getDebug(context: Context, ...tags: [string, any][]): {
7
+ readonly info: (...args: any[]) => void;
8
+ readonly trace: (...args: any[]) => void;
9
+ readonly log: (...args: any[]) => void;
10
+ readonly warn: (...args: any[]) => void;
11
+ readonly error: (...args: any[]) => void;
12
+ };
13
+ export declare function createDebug(name: string, ...tags: [string, any][]): {
14
+ readonly info: (...args: any[]) => void;
15
+ readonly trace: (...args: any[]) => void;
16
+ readonly log: (...args: any[]) => void;
17
+ readonly warn: (...args: any[]) => void;
18
+ readonly error: (...args: any[]) => void;
19
+ };
@@ -1,24 +1,23 @@
1
- export { createApp } from "./app.js";
2
- export { batch, effect, get, memo, readable, signal, untracked, writable } from "./signals.js";
3
- export type { MaybeSignal, Signal, Writable, Setter } from "./signals.js";
4
- export * from "./hooks.js";
5
- export { createContext } from "./context.js";
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, getStore, onCleanup, onEffect, onMount } from "./context.js";
6
6
  export type { Context } from "./context.js";
7
- export { createMarkup, Markup, MarkupNode, render } from "./markup.js";
8
- export { ref, type Ref } from "./ref.js";
9
- export { For, type ForProps } from "./views/for.js";
10
- export { Portal, type PortalProps } from "./views/portal.js";
11
- export { Show, type ShowProps } from "./views/show.js";
12
- export { deepEqual, shallowEqual, strictEqual } from "../utils.js";
13
- export { getEnv, setEnv } from "./env.js";
14
- export { createLogger, onLoggerCrash, setLogFilter, setLogLevels } from "./logger.js";
15
- export type { Logger, LoggerCrashProps, LoggerOptions, LogLevels } from "./logger.js";
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 { forEach, showIf, hideIf, createPortal } 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>;
@@ -0,0 +1,3 @@
1
+ import type { Markup } from "./types.js";
2
+ export type Template = Markup | Markup[];
3
+ export declare function html(statics: TemplateStringsArray, ...args: any[]): Template;
@@ -1,13 +1,14 @@
1
- import { MarkupNode } from "./_markup";
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 root;
7
- constructor(node: Node);
7
+ #private;
8
+ constructor(_context: Context, node: Node);
8
9
  getRoot(): Node;
9
10
  isMounted(): boolean;
10
- mount(parent: Element, after?: Node): void;
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;
@@ -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
- * Returns the currently stored value of the ref, or throws an error if no value has been set.
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
- * Stores a new value to the ref and returns that value.
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): 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;