@manyducks.co/dolla 2.0.0-alpha.34 → 2.0.0-alpha.36
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 +9 -22
- package/dist/core/{batch.d.ts → _batch.d.ts} +4 -0
- package/dist/core/_signals_new.d.ts +130 -0
- package/dist/core/context.d.ts +7 -55
- package/dist/core/dolla.d.ts +7 -48
- package/dist/core/markup.d.ts +9 -31
- package/dist/core/nodes/{observer.d.ts → dynamic.d.ts} +10 -12
- package/dist/core/nodes/html.d.ts +11 -17
- package/dist/core/nodes/list.d.ts +28 -0
- package/dist/core/nodes/outlet.d.ts +7 -7
- package/dist/core/nodes/portal.d.ts +2 -2
- package/dist/core/nodes/view.d.ts +21 -34
- package/dist/core/ref.d.ts +5 -6
- package/dist/core/signals.d.ts +128 -0
- package/dist/core/store.d.ts +14 -18
- package/dist/core/symbols.d.ts +0 -3
- package/dist/{views → core/views}/default-crash-view.d.ts +1 -1
- package/dist/{views → core/views}/passthrough.d.ts +2 -2
- package/dist/{modules/http.d.ts → http/index.d.ts} +1 -2
- package/dist/index.d.ts +8 -11
- package/dist/index.js +517 -695
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/markup-ILMFXzoo.js +1442 -0
- package/dist/markup-ILMFXzoo.js.map +1 -0
- package/dist/{modules/router.d.ts → router/index.d.ts} +5 -5
- package/dist/router/router.utils.test.d.ts +1 -0
- package/dist/{modules/i18n.d.ts → translate/index.d.ts} +20 -16
- package/dist/typeChecking.d.ts +0 -96
- package/dist/types.d.ts +9 -9
- package/dist/utils.d.ts +4 -1
- package/docs/signals.md +149 -0
- package/docs/views.md +1 -87
- package/notes/atomic.md +146 -0
- package/notes/context-routes.md +56 -0
- package/notes/elimination.md +33 -0
- package/package.json +9 -7
- package/vite.config.js +3 -0
- package/dist/core/nodes/repeat.d.ts +0 -36
- package/dist/core/state.d.ts +0 -126
- package/dist/core/stats.d.ts +0 -31
- package/dist/markup-B3FV_fq9.js +0 -1525
- package/dist/markup-B3FV_fq9.js.map +0 -1
- package/notes/viewstate.md +0 -15
- package/tests/state.test.js +0 -135
- /package/dist/{modules/router.utils.test.d.ts → core/signals.test.d.ts} +0 -0
- /package/dist/{modules → router}/router.utils.d.ts +0 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
Dolla is a batteries-included JavaScript frontend framework covering the needs of moderate-to-complex single page apps:
|
|
9
9
|
|
|
10
|
-
- ⚡ Reactive DOM updates with [
|
|
10
|
+
- ⚡ Reactive DOM updates with [Signals](./docs/state.md).
|
|
11
11
|
- 📦 Reusable components with [Views](./docs/views.md).
|
|
12
12
|
- 💾 Reusable state management with [Stores](./docs/stores.md).
|
|
13
13
|
- 🔀 Built-in [routing](./docs/router.md) with nested routes and middleware support (check login status, preload data, etc).
|
|
@@ -25,7 +25,7 @@ Dolla's goals include:
|
|
|
25
25
|
|
|
26
26
|
> TODO: Write about why Dolla was started and what it's all about.
|
|
27
27
|
|
|
28
|
-
- Borne of frustration using React and similar libs (useEffect, referential equality, a pain to integrate other libs into its lifecycle, need to hunt for libraries to move beyond Hello World).
|
|
28
|
+
- Borne of frustration using React and similar libs (useEffect, referential equality, a pain to integrate other libs into its lifecycle, need to hunt for libraries to move much beyond Hello World).
|
|
29
29
|
- Merges ideas from my favorite libraries and frameworks (Solid/Knockout, Choo, Svelte, i18next, etc) into one curated set designed to work well together.
|
|
30
30
|
- Opinionated (with the _correct_ opinions).
|
|
31
31
|
- Many mainstream libraries seem too big for what they do. The entirety of Dolla is less than half the size of [`react-router`](https://bundlephobia.com/package/react-router@7.1.5).
|
|
@@ -35,33 +35,20 @@ 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
|
```js
|
|
38
|
-
import Dolla, {
|
|
38
|
+
import Dolla, { atom, effect, get, html } from "@manyducks.co/dolla";
|
|
39
39
|
|
|
40
40
|
function Counter() {
|
|
41
|
-
const
|
|
41
|
+
const count = atom(0);
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
setCount((count) => count + 1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function decrement() {
|
|
48
|
-
setCount((count) => count - 1);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function reset() {
|
|
52
|
-
setCount(0);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return (
|
|
43
|
+
return html`
|
|
56
44
|
<div>
|
|
57
|
-
<p>
|
|
45
|
+
<p>Counter: ${count}</p>
|
|
58
46
|
<div>
|
|
59
|
-
<button
|
|
60
|
-
<button
|
|
61
|
-
<button onClick={increment}>+1</button>
|
|
47
|
+
<button onclick=${() => count.value--}>-1</button>
|
|
48
|
+
<button onclick=${() => count.value++}>+1</button>
|
|
62
49
|
</div>
|
|
63
50
|
</div>
|
|
64
|
-
|
|
51
|
+
`;
|
|
65
52
|
});
|
|
66
53
|
|
|
67
54
|
Dolla.mount(document.body, Counter);
|
|
@@ -7,11 +7,15 @@ export declare class Batch {
|
|
|
7
7
|
constructor(dolla: Dolla);
|
|
8
8
|
/**
|
|
9
9
|
* Queues a callback that runs before the next batch of writes.
|
|
10
|
+
*
|
|
11
|
+
* @deprecated
|
|
10
12
|
*/
|
|
11
13
|
read(callback: () => void): void;
|
|
12
14
|
/**
|
|
13
15
|
* Queues a callback to run in the next render batch.
|
|
14
16
|
* Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
|
|
17
|
+
*
|
|
18
|
+
* @deprecated
|
|
15
19
|
*/
|
|
16
20
|
write(callback: () => void, key?: string): void;
|
|
17
21
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { type Dependency, type Subscriber } from "alien-signals";
|
|
2
|
+
/**
|
|
3
|
+
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
4
|
+
*/
|
|
5
|
+
export type EqualityFunction<T> = (current: T, next: T) => boolean;
|
|
6
|
+
export interface ReactiveOptions<T> {
|
|
7
|
+
/**
|
|
8
|
+
* A label for debugging purposes.
|
|
9
|
+
*/
|
|
10
|
+
name?: string;
|
|
11
|
+
/**
|
|
12
|
+
* A function to compare the current and next values. Returning `true` means the value has changed.
|
|
13
|
+
*/
|
|
14
|
+
equals?: EqualityFunction<T>;
|
|
15
|
+
}
|
|
16
|
+
export interface Effect extends Subscriber, Dependency {
|
|
17
|
+
name?: string;
|
|
18
|
+
fn(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface Computed<T = any> extends Signal<T | undefined>, Subscriber {
|
|
21
|
+
name?: string;
|
|
22
|
+
getter: (cachedValue?: T) => T;
|
|
23
|
+
equals: EqualityFunction<T>;
|
|
24
|
+
}
|
|
25
|
+
export interface Signal<T = any> extends Dependency {
|
|
26
|
+
name?: string;
|
|
27
|
+
currentValue: T;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A readable reactive state object.
|
|
31
|
+
*/
|
|
32
|
+
export interface Reactive<T> {
|
|
33
|
+
readonly name?: string;
|
|
34
|
+
/**
|
|
35
|
+
* The current value. Read-only.
|
|
36
|
+
*/
|
|
37
|
+
readonly value: T;
|
|
38
|
+
}
|
|
39
|
+
export interface Atom<T> extends Reactive<T> {
|
|
40
|
+
/**
|
|
41
|
+
* The current value.
|
|
42
|
+
*/
|
|
43
|
+
value: T;
|
|
44
|
+
}
|
|
45
|
+
export type MaybeReactive<T> = Reactive<T> | T;
|
|
46
|
+
export type UnsubscribeFunction = () => void;
|
|
47
|
+
/**
|
|
48
|
+
* Determines if a value is reactive.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isReactive<T>(value: any): value is Reactive<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a simple reactive container that stores a value.
|
|
53
|
+
* Atom values can be read and updated with the `value` property
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* const count = atom(1);
|
|
57
|
+
* count.value++;
|
|
58
|
+
* count.value; // 2
|
|
59
|
+
*/
|
|
60
|
+
export declare function atom<T>(): Atom<T | undefined>;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a simple reactive container that stores a value.
|
|
63
|
+
* Atom values can be read and updated with the `value` property.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const count = atom(1);
|
|
67
|
+
* count.value++;
|
|
68
|
+
* count.value; // 2
|
|
69
|
+
*/
|
|
70
|
+
export declare function atom<T>(value: T, options?: ReactiveOptions<T>): Atom<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a simple reactive container that stores a value.
|
|
73
|
+
* Atom values can be read and updated with the `value` property.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* const count = atom(1);
|
|
77
|
+
* count.value++;
|
|
78
|
+
* count.value; // 2
|
|
79
|
+
*/
|
|
80
|
+
export declare function atom<T>(value?: T, options?: ReactiveOptions<T>): Atom<T | undefined>;
|
|
81
|
+
type ComposeCallback<T> = (previousValue?: T) => MaybeReactive<T>;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a reactive container that derives its value from other reactive values that it tracks.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* const count = atom(1);
|
|
87
|
+
* const doubled = compose(() => get(count) * 2);
|
|
88
|
+
*/
|
|
89
|
+
export declare function compose<T>(fn: ComposeCallback<T>, options?: ReactiveOptions<T>): Reactive<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Takes a new value to set, or a callback that receives the current value and returns a new value to set.
|
|
92
|
+
*/
|
|
93
|
+
type Setter<T> = (next: T | ((current: T) => T)) => void;
|
|
94
|
+
export declare function set<T>(atom: Atom<T>): Setter<T>;
|
|
95
|
+
export declare function set<T>(atom: Atom<T>, next: T | ((current: T) => T)): void;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the current value from a reactive _and track it_ if called in a `compose` or `effect` scope.
|
|
98
|
+
* If a non-reactive value is passed it will just be returned untracked.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* const count = atom(1);
|
|
102
|
+
* const value = get(count); // 1
|
|
103
|
+
*
|
|
104
|
+
* const value = get(5); // 5
|
|
105
|
+
*/
|
|
106
|
+
export declare function get<T>(value: MaybeReactive<T>): T;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the current value from a reactive (without tracking).
|
|
109
|
+
* If a non-reactive value is passed it will be returned.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ctx.effect(() => {
|
|
113
|
+
* const doubled = get(count) * 2; // `count` will be tracked
|
|
114
|
+
*
|
|
115
|
+
* const doubled = peek(count) * 2; // `count` will NOT be tracked
|
|
116
|
+
* });
|
|
117
|
+
*/
|
|
118
|
+
export declare function peek<T>(value: MaybeReactive<T>): T;
|
|
119
|
+
export type EffectCallback = () => void;
|
|
120
|
+
/**
|
|
121
|
+
* Creates a tracked scope that re-runs whenever the values of any tracked reactives changes.
|
|
122
|
+
* Reactives are tracked by accessing their `value` within the body of the function.
|
|
123
|
+
*
|
|
124
|
+
* NOTE: You must call the unsubscribe function to stop watching for changes.
|
|
125
|
+
* If you are using an effect inside a View or Store, use `ctx.effect` instead, which cleans up automatically when the component unmounts.
|
|
126
|
+
*/
|
|
127
|
+
export declare function effect(fn: EffectCallback, options?: {
|
|
128
|
+
name?: string;
|
|
129
|
+
}): UnsubscribeFunction;
|
|
130
|
+
export {};
|
package/dist/core/context.d.ts
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
import type { Emitter } from "@manyducks.co/emitter";
|
|
2
1
|
import type { Dolla } from "./dolla";
|
|
3
2
|
import type { Store, StoreFunction } from "./store";
|
|
4
|
-
interface ContextEmitterEvents {
|
|
5
|
-
[eventName: string | symbol]: [ContextEvent, ...args: any[]];
|
|
6
|
-
}
|
|
7
3
|
export interface ElementContext {
|
|
8
4
|
/**
|
|
9
5
|
* The root Dolla instance this element belongs to.
|
|
10
6
|
*/
|
|
11
7
|
root: Dolla;
|
|
12
|
-
/**
|
|
13
|
-
* Storage for context variables.
|
|
14
|
-
*/
|
|
15
|
-
data: Record<string | symbol, unknown>;
|
|
16
|
-
/**
|
|
17
|
-
* Event emitter for this context.
|
|
18
|
-
*/
|
|
19
|
-
emitter: Emitter<ContextEmitterEvents>;
|
|
20
8
|
/**
|
|
21
9
|
* Stores attached to this context.
|
|
22
10
|
*/
|
|
@@ -34,42 +22,16 @@ export interface ElementContext {
|
|
|
34
22
|
*/
|
|
35
23
|
viewName?: string;
|
|
36
24
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Mapping of listener function passed to `.on` -> wrapped versions that discard eventName.
|
|
39
|
-
* Wrapping listeners is necessary because the context API's `.on` method does not pass the event name to "*" listeners while the emitter does.
|
|
40
|
-
* ContextEvent objects already have the event name stored as `event.type`.
|
|
41
|
-
*/
|
|
42
|
-
export type WildcardListenerMap = Map<(event: ContextEvent, ...args: any[]) => void, (eventName: string | symbol, event: ContextEvent, ...args: any[]) => void>;
|
|
43
25
|
export interface ComponentContext {
|
|
44
26
|
/**
|
|
45
|
-
*
|
|
46
|
-
*/
|
|
47
|
-
set<T>(key: string | symbol, value: T): T;
|
|
48
|
-
/**
|
|
49
|
-
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
50
|
-
*/
|
|
51
|
-
get<T>(key: string | symbol): T | null;
|
|
52
|
-
/**
|
|
53
|
-
* Adds a listener to be called when an event with a matching `type` is emitted.
|
|
27
|
+
* A name for debugging purposes. Prepended to log messages.
|
|
54
28
|
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Removes a listener from the list to be called when an event with a matching `type` is emitted.
|
|
58
|
-
*/
|
|
59
|
-
off<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
60
|
-
/**
|
|
61
|
-
* Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
|
|
62
|
-
*/
|
|
63
|
-
once<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
64
|
-
/**
|
|
65
|
-
* Emits a new event to all listeners.
|
|
66
|
-
*/
|
|
67
|
-
emit<T = unknown>(type: string, ...args: any[]): boolean;
|
|
29
|
+
name: string;
|
|
68
30
|
}
|
|
69
31
|
/**
|
|
70
|
-
* A context capable of
|
|
32
|
+
* A context capable of providing stores.
|
|
71
33
|
*/
|
|
72
|
-
export interface
|
|
34
|
+
export interface StoreProviderContext {
|
|
73
35
|
/**
|
|
74
36
|
* Attaches a new store to this context and returns it.
|
|
75
37
|
*/
|
|
@@ -82,20 +44,10 @@ export interface StorableContext extends ComponentContext {
|
|
|
82
44
|
* Attaches a new store to this context and returns it.
|
|
83
45
|
*/
|
|
84
46
|
provide<Options, Value>(store: StoreFunction<Options, Value>, options: Options): Value;
|
|
47
|
+
}
|
|
48
|
+
export interface StoreConsumerContext {
|
|
85
49
|
/**
|
|
86
50
|
* Gets the closest instance of a store. Throws an error if the store isn't provided higher in the tree.
|
|
87
51
|
*/
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* An event emitted from and received by a Dolla context. These are separate from DOM events.
|
|
92
|
-
*/
|
|
93
|
-
export declare class ContextEvent {
|
|
94
|
-
#private;
|
|
95
|
-
constructor(type: string);
|
|
96
|
-
get type(): string;
|
|
97
|
-
get isStopped(): boolean;
|
|
98
|
-
stop(): void;
|
|
99
|
-
get [Symbol.toStringTag](): string;
|
|
52
|
+
get<Value>(store: StoreFunction<any, Value>): Value;
|
|
100
53
|
}
|
|
101
|
-
export {};
|
package/dist/core/dolla.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { HTTP } from "../
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Batch } from "./batch.js";
|
|
6
|
-
import { ContextEvent, type StorableContext } from "./context.js";
|
|
1
|
+
import { HTTP } from "../http/index.js";
|
|
2
|
+
import { type Router } from "../router/index.js";
|
|
3
|
+
import { I18n } from "../translate/index.js";
|
|
4
|
+
import type { StoreConsumerContext, StoreProviderContext } from "./context.js";
|
|
7
5
|
import { type Markup, type MarkupElement } from "./markup.js";
|
|
8
6
|
import { type ViewElement, type ViewFunction } from "./nodes/view.js";
|
|
9
|
-
import { createRef, isRef } from "./ref.js";
|
|
10
|
-
import { createState, createWatcher, derive, isState, toState, toValue } from "./state.js";
|
|
11
7
|
import { StoreFunction } from "./store.js";
|
|
8
|
+
import { type CrashViewProps } from "./views/default-crash-view.js";
|
|
12
9
|
export type Environment = "development" | "production";
|
|
13
10
|
/**
|
|
14
11
|
* Log type toggles. Each message category can be turned on or off or enabled only in a specific environment.
|
|
@@ -42,22 +39,11 @@ export type LoggerOptions = {
|
|
|
42
39
|
*/
|
|
43
40
|
uid?: string;
|
|
44
41
|
};
|
|
45
|
-
export declare class Dolla implements
|
|
42
|
+
export declare class Dolla implements StoreProviderContext, StoreConsumerContext {
|
|
46
43
|
#private;
|
|
47
|
-
readonly batch: Batch;
|
|
48
|
-
private readonly stats;
|
|
49
44
|
readonly http: HTTP;
|
|
50
45
|
readonly i18n: I18n;
|
|
51
46
|
constructor();
|
|
52
|
-
watch: <I extends import("./state.js").MaybeState<any>[]>(states: [...I], fn: (...currentValues: import("./state.js").StateValues<I>) => void) => import("./state.js").StopFunction;
|
|
53
|
-
createState: typeof createState;
|
|
54
|
-
toState: typeof toState;
|
|
55
|
-
toValue: typeof toValue;
|
|
56
|
-
isState: typeof isState;
|
|
57
|
-
derive: typeof derive;
|
|
58
|
-
createWatcher: typeof createWatcher;
|
|
59
|
-
createRef: typeof createRef;
|
|
60
|
-
isRef: typeof isRef;
|
|
61
47
|
/**
|
|
62
48
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
63
49
|
*/
|
|
@@ -85,33 +71,6 @@ export declare class Dolla implements StorableContext {
|
|
|
85
71
|
* Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
|
|
86
72
|
*/
|
|
87
73
|
getRootView(): ViewElement | undefined;
|
|
88
|
-
/**
|
|
89
|
-
* Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
|
|
90
|
-
*/
|
|
91
|
-
set<T>(key: string | symbol, value: T): T;
|
|
92
|
-
/**
|
|
93
|
-
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
94
|
-
*/
|
|
95
|
-
get<T>(key: string | symbol): T | null;
|
|
96
|
-
/**
|
|
97
|
-
* Returns an object of all context variables stored at the app level.
|
|
98
|
-
*/
|
|
99
|
-
/**
|
|
100
|
-
* Adds a listener to be called when an event with a matching `type` is emitted.
|
|
101
|
-
*/
|
|
102
|
-
on<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
103
|
-
/**
|
|
104
|
-
* Removes a listener from the list to be called when an event with a matching `type` is emitted.
|
|
105
|
-
*/
|
|
106
|
-
off<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
107
|
-
/**
|
|
108
|
-
* Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
|
|
109
|
-
*/
|
|
110
|
-
once<T = unknown>(type: string, listener: (event: ContextEvent, ...args: any[]) => void): void;
|
|
111
|
-
/**
|
|
112
|
-
* Emits a new event to all listeners.
|
|
113
|
-
*/
|
|
114
|
-
emit<T = unknown>(type: string, ...args: any[]): boolean;
|
|
115
74
|
/**
|
|
116
75
|
* Attaches a new store to this context.
|
|
117
76
|
*/
|
|
@@ -127,7 +86,7 @@ export declare class Dolla implements StorableContext {
|
|
|
127
86
|
/**
|
|
128
87
|
* Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
|
|
129
88
|
*/
|
|
130
|
-
|
|
89
|
+
get<Value>(store: StoreFunction<any, Value>): Value;
|
|
131
90
|
mount(selector: string, router: Router): Promise<void>;
|
|
132
91
|
mount(selector: string, view: ViewFunction<any>): Promise<void>;
|
|
133
92
|
mount(element: Element, router: Router): Promise<void>;
|
package/dist/core/markup.d.ts
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
import type { Renderable } from "../types.js";
|
|
2
2
|
import type { ElementContext } from "./context.js";
|
|
3
3
|
import { type ViewContext, type ViewFunction, type ViewResult } from "./nodes/view.js";
|
|
4
|
-
import {
|
|
5
|
-
import { IS_MARKUP } from "./symbols.js";
|
|
6
|
-
export declare class _Markup implements Markup {
|
|
7
|
-
[IS_MARKUP]: boolean;
|
|
8
|
-
static text(value: MaybeState<string>): _Markup;
|
|
9
|
-
static from(renderable: Renderable): Markup;
|
|
10
|
-
/**
|
|
11
|
-
* In the case of a view, type will be the View function itself. It can also hold an identifier for special nodes like "$cond", "$repeat", etc.
|
|
12
|
-
* DOM nodes can be created by name, such as HTML elements like "div", "ul" or "span", SVG elements like ""
|
|
13
|
-
*/
|
|
14
|
-
type: string | ViewFunction<any>;
|
|
15
|
-
/**
|
|
16
|
-
* Data that will be passed to a new MarkupElement instance when it is constructed.
|
|
17
|
-
*/
|
|
18
|
-
props: Record<string, any> | undefined;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
children: Markup[];
|
|
23
|
-
constructor(type: string | ViewFunction<any>, props?: Record<string, any>, children?: Renderable[]);
|
|
24
|
-
toElement(context: ElementContext): MarkupElement;
|
|
25
|
-
}
|
|
4
|
+
import { MaybeReactive, type Reactive } from "./signals.js";
|
|
26
5
|
/**
|
|
27
6
|
* Markup is a set of element metadata that hasn't been constructed into a MarkupElement yet.
|
|
28
7
|
*/
|
|
@@ -61,17 +40,16 @@ export interface MarkupAttributes {
|
|
|
61
40
|
$text: {
|
|
62
41
|
value: any;
|
|
63
42
|
};
|
|
64
|
-
$
|
|
65
|
-
|
|
43
|
+
$list: {
|
|
44
|
+
items: Reactive<any[]>;
|
|
66
45
|
keyFn: (value: any, index: number) => string | number | symbol;
|
|
67
|
-
renderFn: (
|
|
46
|
+
renderFn: (item: Reactive<any>, index: Reactive<number>, ctx: ViewContext) => ViewResult;
|
|
68
47
|
};
|
|
69
|
-
$
|
|
70
|
-
|
|
71
|
-
renderFn: (...items: any) => Renderable;
|
|
48
|
+
$dynamic: {
|
|
49
|
+
source: Reactive<Renderable>;
|
|
72
50
|
};
|
|
73
51
|
$outlet: {
|
|
74
|
-
|
|
52
|
+
children: MaybeReactive<MarkupElement[]>;
|
|
75
53
|
};
|
|
76
54
|
$node: {
|
|
77
55
|
value: Node;
|
|
@@ -91,12 +69,12 @@ export declare const html: (strings: TemplateStringsArray, ...values: any[]) =>
|
|
|
91
69
|
/**
|
|
92
70
|
* Displays content conditionally. When `condition` holds a truthy value, `thenContent` is displayed; when `condition` holds a falsy value, `elseContent` is displayed.
|
|
93
71
|
*/
|
|
94
|
-
export declare function cond(condition:
|
|
72
|
+
export declare function cond(condition: MaybeReactive<any>, thenContent?: Renderable, elseContent?: Renderable): Markup;
|
|
95
73
|
/**
|
|
96
74
|
* Calls `renderFn` for each item in `items`. Dynamically adds and removes views as items change.
|
|
97
75
|
* The result of `keyFn` is used to compare items and decide if item was added, removed or updated.
|
|
98
76
|
*/
|
|
99
|
-
export declare function
|
|
77
|
+
export declare function list<T>(items: MaybeReactive<T[]>, keyFn: (value: T, index: number) => string | number | symbol, renderFn: (item: Reactive<T>, index: Reactive<number>, ctx: ViewContext) => ViewResult): Markup;
|
|
100
78
|
/**
|
|
101
79
|
* Renders `content` into a `parent` node anywhere in the page, rather than its usual position in the view.
|
|
102
80
|
*/
|
|
@@ -1,27 +1,25 @@
|
|
|
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 { type
|
|
4
|
+
import { type Reactive } from "../signals.js";
|
|
5
5
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
6
|
-
interface
|
|
6
|
+
interface DynamicOptions {
|
|
7
|
+
source: Reactive<Renderable>;
|
|
7
8
|
elementContext: ElementContext;
|
|
8
|
-
sources: MaybeState<any>[];
|
|
9
|
-
renderFn: (...values: any) => Renderable;
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* Displays dynamic children without a parent element.
|
|
13
|
-
*
|
|
12
|
+
* Renders a Reactive value via a render function.
|
|
14
13
|
*/
|
|
15
|
-
export declare class
|
|
14
|
+
export declare class Dynamic implements MarkupElement {
|
|
16
15
|
[IS_MARKUP_ELEMENT]: boolean;
|
|
17
16
|
node: Text;
|
|
18
|
-
children
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
sources: MaybeState<any>[];
|
|
17
|
+
private children;
|
|
18
|
+
private elementContext;
|
|
19
|
+
private source;
|
|
20
|
+
private unsubscribe?;
|
|
23
21
|
get isMounted(): boolean;
|
|
24
|
-
constructor(
|
|
22
|
+
constructor(options: DynamicOptions);
|
|
25
23
|
mount(parent: Node, after?: Node): void;
|
|
26
24
|
unmount(parentIsUnmounting?: boolean): void;
|
|
27
25
|
cleanup(parentIsUnmounting: boolean): void;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type ElementContext } from "../context.js";
|
|
2
2
|
import { type Markup, type MarkupElement } from "../markup.js";
|
|
3
|
-
import { type Ref } from "../ref.js";
|
|
4
|
-
import { type State, type StopFunction } from "../state.js";
|
|
5
3
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
6
4
|
type HTMLOptions = {
|
|
7
5
|
elementContext: ElementContext;
|
|
@@ -12,25 +10,21 @@ type HTMLOptions = {
|
|
|
12
10
|
export declare class HTML implements MarkupElement {
|
|
13
11
|
[IS_MARKUP_ELEMENT]: boolean;
|
|
14
12
|
node: HTMLElement | SVGElement;
|
|
15
|
-
props
|
|
16
|
-
childMarkup
|
|
17
|
-
children
|
|
18
|
-
|
|
19
|
-
elementContext
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
ref?: Ref<any>;
|
|
23
|
-
canClickAway: boolean;
|
|
13
|
+
private props;
|
|
14
|
+
private childMarkup;
|
|
15
|
+
private children;
|
|
16
|
+
private unsubscribers;
|
|
17
|
+
private elementContext;
|
|
18
|
+
private ref?;
|
|
19
|
+
private canClickAway;
|
|
24
20
|
get isMounted(): boolean;
|
|
25
21
|
constructor({ tag, props, children, elementContext }: HTMLOptions);
|
|
26
22
|
mount(parent: Node, after?: Node): void;
|
|
27
23
|
unmount(parentIsUnmounting?: boolean): void;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
applyStyles(element: HTMLElement | SVGElement, styles: unknown, stopCallbacks: StopFunction[]): () => void;
|
|
33
|
-
applyClasses(element: HTMLElement | SVGElement, classes: unknown, stopCallbacks: StopFunction[]): () => void;
|
|
24
|
+
private attachProp;
|
|
25
|
+
private applyProps;
|
|
26
|
+
private applyStyles;
|
|
27
|
+
private applyClasses;
|
|
34
28
|
}
|
|
35
29
|
/**
|
|
36
30
|
* Converts a camelCase string to kebab-case.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ElementContext } from "../context.js";
|
|
2
|
+
import { type MarkupElement } from "../markup.js";
|
|
3
|
+
import { type Reactive } from "../signals.js";
|
|
4
|
+
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
5
|
+
import { type ViewContext, type ViewResult } from "./view.js";
|
|
6
|
+
interface ListOptions<T> {
|
|
7
|
+
elementContext: ElementContext;
|
|
8
|
+
items: Reactive<T[]>;
|
|
9
|
+
keyFn: (item: T, index: number) => string | number | symbol;
|
|
10
|
+
renderFn: (item: Reactive<T>, index: Reactive<number>, ctx: ViewContext) => ViewResult;
|
|
11
|
+
}
|
|
12
|
+
export declare class List<T> implements MarkupElement {
|
|
13
|
+
[IS_MARKUP_ELEMENT]: boolean;
|
|
14
|
+
node: Text;
|
|
15
|
+
private items;
|
|
16
|
+
private unsubscribe;
|
|
17
|
+
private connectedItems;
|
|
18
|
+
private elementContext;
|
|
19
|
+
private renderFn;
|
|
20
|
+
private keyFn;
|
|
21
|
+
get isMounted(): boolean;
|
|
22
|
+
constructor({ elementContext, items, renderFn, keyFn }: ListOptions<T>);
|
|
23
|
+
mount(parent: Node, after?: Node): void;
|
|
24
|
+
unmount(parentIsUnmounting?: boolean): void;
|
|
25
|
+
private _cleanup;
|
|
26
|
+
private _update;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type MarkupElement } from "../markup.js";
|
|
2
|
-
import { type
|
|
2
|
+
import { type MaybeReactive } from "../signals.js";
|
|
3
3
|
import { IS_MARKUP_ELEMENT } from "../symbols.js";
|
|
4
4
|
/**
|
|
5
5
|
* Manages several MarkupElements as one.
|
|
@@ -8,12 +8,12 @@ export declare class Outlet implements MarkupElement {
|
|
|
8
8
|
[IS_MARKUP_ELEMENT]: boolean;
|
|
9
9
|
node: Text;
|
|
10
10
|
isMounted: boolean;
|
|
11
|
-
source
|
|
12
|
-
elements
|
|
13
|
-
|
|
14
|
-
constructor(source:
|
|
11
|
+
private source;
|
|
12
|
+
private elements;
|
|
13
|
+
private unsubscribe?;
|
|
14
|
+
constructor(source: MaybeReactive<MarkupElement[]>);
|
|
15
15
|
mount(parent: Node, after?: Node | undefined): void;
|
|
16
16
|
unmount(parentIsUnmounting?: boolean): void;
|
|
17
|
-
cleanup
|
|
18
|
-
update
|
|
17
|
+
private cleanup;
|
|
18
|
+
private update;
|
|
19
19
|
}
|
|
@@ -12,8 +12,8 @@ interface PortalConfig {
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class Portal implements MarkupElement {
|
|
14
14
|
[IS_MARKUP_ELEMENT]: boolean;
|
|
15
|
-
config
|
|
16
|
-
element
|
|
15
|
+
private config;
|
|
16
|
+
private element?;
|
|
17
17
|
get isMounted(): boolean;
|
|
18
18
|
constructor(config: PortalConfig);
|
|
19
19
|
mount(_parent: Node, _after?: Node): void;
|