@manyducks.co/dolla 2.0.0-alpha.9 → 2.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.
- package/README.md +222 -512
- package/dist/core/app.d.ts +24 -0
- package/dist/core/context.d.ts +147 -0
- package/dist/core/env.d.ts +3 -0
- package/dist/core/hooks.d.ts +70 -0
- package/dist/core/hooks.test.d.ts +1 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/logger.d.ts +42 -0
- package/dist/core/logger.test.d.ts +0 -0
- package/dist/core/markup.d.ts +82 -0
- package/dist/core/markup.test.d.ts +0 -0
- package/dist/core/nodes/_markup.d.ts +36 -0
- package/dist/core/nodes/dom.d.ts +13 -0
- package/dist/core/nodes/dynamic.d.ts +22 -0
- package/dist/core/nodes/element.d.ts +27 -0
- package/dist/core/nodes/portal.d.ts +18 -0
- package/dist/core/nodes/repeat.d.ts +27 -0
- package/dist/core/nodes/view.d.ts +25 -0
- package/dist/core/ref.d.ts +19 -0
- package/dist/core/ref.test.d.ts +1 -0
- package/dist/core/signals.d.ts +100 -0
- package/dist/core/signals.test.d.ts +1 -0
- package/dist/{views → core/views}/default-crash-view.d.ts +11 -4
- package/dist/core/views/for.d.ts +21 -0
- package/dist/core/views/fragment.d.ts +7 -0
- package/dist/core/views/portal.d.ts +16 -0
- package/dist/core/views/show.d.ts +25 -0
- package/dist/fragment-BahD_BJA.js +7 -0
- package/dist/fragment-BahD_BJA.js.map +1 -0
- package/dist/{modules/http.d.ts → http/index.d.ts} +3 -5
- package/dist/http.js +150 -0
- package/dist/http.js.map +1 -0
- package/dist/i18n/index.d.ts +134 -0
- package/dist/i18n.js +309 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index-DRJlxs-Q.js +535 -0
- package/dist/index-DRJlxs-Q.js.map +1 -0
- package/dist/index.js +160 -1414
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +3 -2
- package/dist/jsx-dev-runtime.js +5 -12
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +4 -3
- package/dist/jsx-runtime.js +9 -15
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/logger-Aqi9m1CF.js +565 -0
- package/dist/logger-Aqi9m1CF.js.map +1 -0
- package/dist/markup-8jNhoqDe.js +1089 -0
- package/dist/markup-8jNhoqDe.js.map +1 -0
- package/dist/router/hooks.d.ts +2 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/router.d.ts +166 -0
- package/dist/{routing.d.ts → router/router.utils.d.ts} +17 -3
- package/dist/router/router.utils.test.d.ts +1 -0
- package/dist/router.js +6 -0
- package/dist/router.js.map +1 -0
- package/dist/typeChecking-5kmX0ulW.js +65 -0
- package/dist/typeChecking-5kmX0ulW.js.map +1 -0
- package/dist/typeChecking.d.ts +2 -98
- package/dist/typeChecking.test.d.ts +1 -0
- package/dist/types.d.ts +97 -25
- package/dist/utils.d.ts +25 -3
- package/docs/buildless.md +132 -0
- package/docs/components.md +238 -0
- package/docs/hooks.md +356 -0
- package/docs/http.md +178 -0
- package/docs/i18n.md +220 -0
- package/docs/index.md +10 -0
- package/docs/markup.md +136 -0
- package/docs/mixins.md +176 -0
- package/docs/ref.md +77 -0
- package/docs/router.md +281 -0
- package/docs/setup.md +137 -0
- package/docs/signals.md +262 -0
- package/docs/stores.md +113 -0
- package/docs/views.md +356 -0
- package/index.d.ts +2 -2
- package/notes/atomic.md +452 -0
- package/notes/elimination.md +33 -0
- package/notes/observable.md +180 -0
- package/notes/scratch.md +346 -14
- package/notes/splitting.md +5 -0
- package/package.json +29 -15
- package/vite.config.js +5 -11
- package/build.js +0 -34
- package/dist/index.d.ts +0 -21
- package/dist/markup.d.ts +0 -108
- package/dist/modules/dolla.d.ts +0 -111
- package/dist/modules/i18n.d.ts +0 -59
- package/dist/modules/render.d.ts +0 -17
- package/dist/modules/router.d.ts +0 -152
- package/dist/nodes/cond.d.ts +0 -26
- package/dist/nodes/html.d.ts +0 -31
- package/dist/nodes/observer.d.ts +0 -29
- package/dist/nodes/outlet.d.ts +0 -22
- package/dist/nodes/portal.d.ts +0 -19
- package/dist/nodes/repeat.d.ts +0 -34
- package/dist/nodes/text.d.ts +0 -19
- package/dist/passthrough-9kwwjgWk.js +0 -1279
- package/dist/passthrough-9kwwjgWk.js.map +0 -1
- package/dist/state.d.ts +0 -101
- package/dist/view.d.ts +0 -65
- package/dist/views/passthrough.d.ts +0 -5
- package/notes/context-vars.md +0 -21
- package/notes/readme-scratch.md +0 -222
- package/notes/route-middleware.md +0 -42
- package/tests/state.test.js +0 -135
- /package/dist/{routing.test.d.ts → core/context.test.d.ts} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Router, RouterOptions } from "../router/router";
|
|
2
|
+
import { View } from "../types";
|
|
3
|
+
import { Context } from "./context";
|
|
4
|
+
import { LoggerCrashProps } from "./logger";
|
|
5
|
+
interface AppOptions {
|
|
6
|
+
view?: View<{}>;
|
|
7
|
+
router?: Router;
|
|
8
|
+
context?: Context;
|
|
9
|
+
}
|
|
10
|
+
declare class App {
|
|
11
|
+
#private;
|
|
12
|
+
get context(): Context;
|
|
13
|
+
constructor(options: AppOptions);
|
|
14
|
+
setCrashView(view: View<LoggerCrashProps>): this;
|
|
15
|
+
mount(element: string | Element): Promise<void>;
|
|
16
|
+
unmount(): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface CreateAppOptions {
|
|
19
|
+
context?: Context;
|
|
20
|
+
}
|
|
21
|
+
export declare function createApp(view: View<{}>, options?: CreateAppOptions): App;
|
|
22
|
+
export declare function createApp(routerOptions: RouterOptions, options?: CreateAppOptions): App;
|
|
23
|
+
export declare function createApp(router: Router, options?: CreateAppOptions): App;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,147 @@
|
|
|
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;
|
|
147
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type Context, type Ref, type Store } from "../core";
|
|
2
|
+
import { type EffectFn, type MaybeSignal, type Setter, type Signal, type SignalOptions } from "../core/signals";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the Context object of the `View`, `Store` or `Mixin` this hook is called in.
|
|
5
|
+
*
|
|
6
|
+
* @param name - If passed, the context will be renamed. Context takes the name of the component function by default.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useContext(name?: MaybeSignal<string>): Context;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the nearest instance of a Store provided to this context.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useStore<T>(store: Store<any, T>): T;
|
|
13
|
+
/**
|
|
14
|
+
* Adds a store to this context and returns the store instance.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useStoreProvider<T, O>(store: Store<O, T>, options?: O): T;
|
|
17
|
+
/**
|
|
18
|
+
* Schedules `callback` to run just after the component is mounted.
|
|
19
|
+
* If `callback` returns a function, that function will run when the context is unmounted.
|
|
20
|
+
*/
|
|
21
|
+
export declare function useMount(callback: () => void | (() => void)): void;
|
|
22
|
+
/**
|
|
23
|
+
* Schedules `callback` to run when the context is unmounted.
|
|
24
|
+
*/
|
|
25
|
+
export declare function useUnmount(callback: () => void): void;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new read-only Signal. Returns bound Getter and Setter functions.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const [$count, setCount] = useSignal(5);
|
|
31
|
+
* $count(); // 5
|
|
32
|
+
* setCount(6);
|
|
33
|
+
* setCount((current) => current + 1);
|
|
34
|
+
* $count(); // 7
|
|
35
|
+
*/
|
|
36
|
+
export declare function useSignal<T>(value: T, options?: SignalOptions<T>): [Signal<T>, Setter<T>];
|
|
37
|
+
export declare function useSignal<T>(value: undefined, options: SignalOptions<T>): [Signal<T | undefined>, Setter<T | undefined>];
|
|
38
|
+
export declare function useSignal<T>(): [Signal<T | undefined>, Setter<T | undefined>];
|
|
39
|
+
export declare function useMemo<T>(compute: (current?: T) => MaybeSignal<T>, deps?: Signal<any>[], options?: SignalOptions<T>): Signal<T>;
|
|
40
|
+
/**
|
|
41
|
+
* Takes the current state and a dispatched action. Returns a new state based on the action.
|
|
42
|
+
* Typically the body of this function will be a large switch statement.
|
|
43
|
+
*/
|
|
44
|
+
export type Reducer<State, Action> = (state: State, action: Action) => State;
|
|
45
|
+
/**
|
|
46
|
+
* Dispatches an action to this reducer, causing the state to update.
|
|
47
|
+
*/
|
|
48
|
+
export type Dispatcher<Action> = (action: Action) => void;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
export declare function useReducer<State, Action>(reducer: Reducer<State, Action>, initialState: State): [Signal<State>, Dispatcher<Action>];
|
|
53
|
+
/**
|
|
54
|
+
* Creates an effect bound to the current context.
|
|
55
|
+
* The `fn` is called when the component is mounted, then again each time the dependencies are updated until the component is unmounted.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useEffect(fn: EffectFn, deps?: Signal<any>[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* A hybrid Ref which is both a function ref and a React-style object ref with a `current` property.
|
|
60
|
+
* Both the `current` property and the function syntax access the same value.
|
|
61
|
+
*/
|
|
62
|
+
export interface HybridRef<T> extends Ref<T> {
|
|
63
|
+
current: T;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creates a Ref. Useful for getting references to DOM nodes.
|
|
67
|
+
*
|
|
68
|
+
* @deprecated use ref()
|
|
69
|
+
*/
|
|
70
|
+
export declare function useRef<T>(initialValue?: T): HybridRef<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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";
|
|
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";
|
|
18
|
+
import type { IntrinsicElements as Elements } from "../types.js";
|
|
19
|
+
declare global {
|
|
20
|
+
namespace JSX {
|
|
21
|
+
interface IntrinsicElements extends Elements {
|
|
22
|
+
[tag: string]: any;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Env } from "../types.js";
|
|
2
|
+
import { type MaybeSignal } from "./signals.js";
|
|
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): Error;
|
|
15
|
+
}
|
|
16
|
+
export interface LoggerOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Tag value to print with logs.
|
|
19
|
+
*/
|
|
20
|
+
tag?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Label for tag value. Will be printed without a label if not specified.
|
|
23
|
+
*/
|
|
24
|
+
tagName?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Console object to use for logging (mostly for testing). Uses window.console by default.
|
|
27
|
+
*/
|
|
28
|
+
console?: any;
|
|
29
|
+
}
|
|
30
|
+
export interface LoggerCrashProps {
|
|
31
|
+
error: Error;
|
|
32
|
+
loggerName: string;
|
|
33
|
+
tag?: string;
|
|
34
|
+
tagName?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Listen for logged crashes.
|
|
38
|
+
*/
|
|
39
|
+
export declare function onLoggerCrash(listener: (context: LoggerCrashProps) => void): () => void;
|
|
40
|
+
export declare function createLogger(name: MaybeSignal<string>, options?: LoggerOptions): Logger;
|
|
41
|
+
export declare function setLogFilter(filter: string | RegExp): void;
|
|
42
|
+
export declare function setLogLevels(options: Partial<LogLevels>): void;
|
|
File without changes
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { IntrinsicElements, Renderable, View } from "../types.js";
|
|
2
|
+
import { Context } from "./context.js";
|
|
3
|
+
import { MarkupNode } from "./nodes/_markup.js";
|
|
4
|
+
import { KeyFn, RenderFn } from "./nodes/repeat.js";
|
|
5
|
+
import { type Signal } from "./signals.js";
|
|
6
|
+
export { MarkupNode };
|
|
7
|
+
type PropsOf<V extends string | View<any>> = V extends View<infer U> ? U : any;
|
|
8
|
+
/**
|
|
9
|
+
* `Markup` is a set of metadata that will be constructed into a `MarkupNode`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Markup<Type extends string | View<any> = string | View<any>> {
|
|
12
|
+
/**
|
|
13
|
+
* 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.
|
|
14
|
+
* DOM nodes can be created by name, such as HTML elements like "div", "ul" or "span", SVG elements like ""
|
|
15
|
+
*/
|
|
16
|
+
type: Type;
|
|
17
|
+
/**
|
|
18
|
+
* Data that will be passed to a new MarkupNode instance when it is constructed.
|
|
19
|
+
* Includes a `children` prop if children were passed.
|
|
20
|
+
*/
|
|
21
|
+
props: PropsOf<Type>;
|
|
22
|
+
constructor(type: Type, props: PropsOf<Type>);
|
|
23
|
+
}
|
|
24
|
+
export declare enum MarkupType {
|
|
25
|
+
DOM = "$dom",
|
|
26
|
+
Dynamic = "$dynamic",
|
|
27
|
+
Portal = "$portal",
|
|
28
|
+
Repeat = "$repeat"
|
|
29
|
+
}
|
|
30
|
+
export interface MarkupNodeProps {
|
|
31
|
+
[MarkupType.DOM]: {
|
|
32
|
+
value: Node;
|
|
33
|
+
};
|
|
34
|
+
[MarkupType.Dynamic]: {
|
|
35
|
+
source: Signal<any>;
|
|
36
|
+
};
|
|
37
|
+
[MarkupType.Portal]: {
|
|
38
|
+
content: Renderable;
|
|
39
|
+
parent: Element;
|
|
40
|
+
};
|
|
41
|
+
[MarkupType.Repeat]: {
|
|
42
|
+
items: Signal<any[]>;
|
|
43
|
+
key: KeyFn<any>;
|
|
44
|
+
render: RenderFn<any>;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface MarkupCustomElementProps {
|
|
48
|
+
/**
|
|
49
|
+
* Custom element tagName pattern (must include a hyphen).
|
|
50
|
+
*/
|
|
51
|
+
[tag: `${string}-${string}`]: Record<string, any>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates a `Markup` element that defines an HTML element.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createMarkup<T extends keyof IntrinsicElements>(tag: T, attrs: IntrinsicElements[T] & {
|
|
57
|
+
children?: Renderable;
|
|
58
|
+
}): Markup;
|
|
59
|
+
/**
|
|
60
|
+
* Creates a `Markup` element that defines an HTML custom element.
|
|
61
|
+
*/
|
|
62
|
+
export declare function createMarkup<T extends keyof MarkupCustomElementProps>(type: T, props: MarkupCustomElementProps[T]): Markup;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a `Markup` element that defines a `MarkupNode`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function createMarkup<T extends keyof MarkupNodeProps>(type: T, props: MarkupNodeProps[T]): Markup;
|
|
67
|
+
/**
|
|
68
|
+
* Creates a `Markup` element that defines a view.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createMarkup<P extends {}>(type: View<P>, props?: P): Markup;
|
|
71
|
+
/**
|
|
72
|
+
* Creates a `Markup` element that defines a view.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createMarkup<P>(type: View<P>, props: P): Markup;
|
|
75
|
+
/**
|
|
76
|
+
* Takes any `Renderable` value and returns a `MarkupNode` that will display it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function render(content: Renderable, context?: Context): MarkupNode;
|
|
79
|
+
/**
|
|
80
|
+
* Convert basically anything into a set of `MarkupNode`s.
|
|
81
|
+
*/
|
|
82
|
+
export declare function toMarkupNodes(context: Context, ...content: any[]): MarkupNode[];
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A node that can be mounted by the Markup layout engine. Can be extended to create new custom node types.
|
|
3
|
+
*
|
|
4
|
+
* A `MarkupNode` instance can be passed anywhere a `Renderable` is required.
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class MarkupNode {
|
|
7
|
+
/**
|
|
8
|
+
* Returns a single DOM node to represent this MarkupNode's position in the DOM.
|
|
9
|
+
* Usually the parent element, but it can be an empty Text node used as a marker.
|
|
10
|
+
*
|
|
11
|
+
* It only needs to be defined while the node is mounted, so it can be created in the `mount` function.
|
|
12
|
+
*/
|
|
13
|
+
getRoot(): Node | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Returns true while this node is mounted.
|
|
16
|
+
*/
|
|
17
|
+
isMounted(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Mount this node to a `parent` element.
|
|
20
|
+
* If passed, this node will be mounted as the next sibling of `after`.
|
|
21
|
+
*/
|
|
22
|
+
mount(parent: Element, after?: Node): void;
|
|
23
|
+
/**
|
|
24
|
+
* Unmount this MarkupNode from its parent element.
|
|
25
|
+
*
|
|
26
|
+
* The `skipDOM` option can be passed as an optimization when unmounting a parent node.
|
|
27
|
+
* A value of `true` indicates that no DOM operations need to happen because the parent is already being unmounted.
|
|
28
|
+
*
|
|
29
|
+
* @param skipDOM - No DOM updates will be performed when true. Lifecycle methods will be called regardless.
|
|
30
|
+
*/
|
|
31
|
+
unmount(skipDOM?: boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* Moves a node without unmounting and remounting (if the browser supports Element.moveBefore).
|
|
34
|
+
*/
|
|
35
|
+
move(parent: Element, after?: Node): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MarkupNode } from "./_markup";
|
|
2
|
+
/**
|
|
3
|
+
* A lightweight MarkupNode wrapper for a plain DOM node.
|
|
4
|
+
*/
|
|
5
|
+
export declare class DOMNode extends MarkupNode {
|
|
6
|
+
private root;
|
|
7
|
+
constructor(node: Node);
|
|
8
|
+
getRoot(): Node;
|
|
9
|
+
isMounted(): boolean;
|
|
10
|
+
mount(parent: Element, after?: Node): void;
|
|
11
|
+
unmount(skipDOM?: boolean): void;
|
|
12
|
+
move(parent: Element, after?: Node): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Context } from "../context.js";
|
|
2
|
+
import { type Signal } from "../signals.js";
|
|
3
|
+
import { MarkupNode } from "./_markup.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 root;
|
|
10
|
+
private children;
|
|
11
|
+
private context;
|
|
12
|
+
private $slot;
|
|
13
|
+
private unsubscribe?;
|
|
14
|
+
constructor(context: Context, $slot: Signal<any>);
|
|
15
|
+
getRoot(): Text;
|
|
16
|
+
isMounted(): boolean;
|
|
17
|
+
mount(parent: Node, after?: Node): void;
|
|
18
|
+
unmount(skipDOM?: boolean): void;
|
|
19
|
+
move(parent: Element, after?: Node): void;
|
|
20
|
+
private cleanup;
|
|
21
|
+
private update;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Context } from "../context.js";
|
|
2
|
+
import { MarkupNode } from "./_markup.js";
|
|
3
|
+
/**
|
|
4
|
+
* Renders an HTML or SVG element.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ElementNode extends MarkupNode {
|
|
7
|
+
private root;
|
|
8
|
+
private id;
|
|
9
|
+
readonly tag: string;
|
|
10
|
+
readonly props: Record<string, any>;
|
|
11
|
+
private context;
|
|
12
|
+
private childNodes;
|
|
13
|
+
private unsubscribers;
|
|
14
|
+
private ref?;
|
|
15
|
+
private canClickAway;
|
|
16
|
+
constructor(context: Context, tag: string, props: Record<string, any>);
|
|
17
|
+
getRoot(): HTMLElement | SVGElement;
|
|
18
|
+
isMounted(): boolean;
|
|
19
|
+
mount(parent: Node, after?: Node): void;
|
|
20
|
+
unmount(skipDOM?: boolean): void;
|
|
21
|
+
move(parent: Element, after?: Node): void;
|
|
22
|
+
private attachProp;
|
|
23
|
+
private getKey;
|
|
24
|
+
private applyProps;
|
|
25
|
+
private applyStyles;
|
|
26
|
+
private applyClasses;
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Renderable } from "../../types.js";
|
|
2
|
+
import { Context } from "../context.js";
|
|
3
|
+
import { MarkupNode } from "./_markup.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders content into a specified parent node.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PortalNode extends MarkupNode {
|
|
8
|
+
private context;
|
|
9
|
+
private value;
|
|
10
|
+
private parent;
|
|
11
|
+
private node?;
|
|
12
|
+
constructor(context: Context, value: Renderable, parent: Element);
|
|
13
|
+
getRoot(): Node | undefined;
|
|
14
|
+
isMounted(): boolean;
|
|
15
|
+
mount(_parent: Element, _after?: Node): void;
|
|
16
|
+
unmount(skipDOM?: boolean): void;
|
|
17
|
+
move(_parent: Element, _after?: Node): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Renderable } from "../../types.js";
|
|
2
|
+
import type { Context } from "../context.js";
|
|
3
|
+
import { type Signal } from "../signals.js";
|
|
4
|
+
import { MarkupNode } from "./_markup.js";
|
|
5
|
+
export type Key = any;
|
|
6
|
+
export type KeyFn<T> = (item: T, index: number) => Key;
|
|
7
|
+
export type RenderFn<T> = (item: Signal<T>, index: Signal<number>) => Renderable;
|
|
8
|
+
/**
|
|
9
|
+
* Renders a list of items.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RepeatNode<T> extends MarkupNode {
|
|
12
|
+
private root;
|
|
13
|
+
private context;
|
|
14
|
+
private items;
|
|
15
|
+
private key;
|
|
16
|
+
private render;
|
|
17
|
+
private unsubscribe;
|
|
18
|
+
private connectedItems;
|
|
19
|
+
constructor(context: Context, items: Signal<T[]>, key: KeyFn<T>, render: RenderFn<T>);
|
|
20
|
+
getRoot(): Text;
|
|
21
|
+
isMounted(): boolean;
|
|
22
|
+
mount(parent: Element, after?: Node): void;
|
|
23
|
+
unmount(skipDOM?: boolean): void;
|
|
24
|
+
move(parent: Element, after?: Node): void;
|
|
25
|
+
private _cleanup;
|
|
26
|
+
private _update;
|
|
27
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { View } from "../../types.js";
|
|
2
|
+
import { Context } from "../context.js";
|
|
3
|
+
import { MarkupNode } from "./_markup.js";
|
|
4
|
+
export declare const VIEW: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* Renders a View.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ViewNode<P> extends MarkupNode {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly props: P;
|
|
11
|
+
readonly context: Context;
|
|
12
|
+
readonly view: View<P>;
|
|
13
|
+
node?: MarkupNode;
|
|
14
|
+
/**
|
|
15
|
+
* @param context - Parent contenxt to link to.
|
|
16
|
+
* @param view - View function to mount.
|
|
17
|
+
* @param props - Props to pass to view function.
|
|
18
|
+
*/
|
|
19
|
+
constructor(context: Context, view: View<P>, props: P);
|
|
20
|
+
getRoot(): Node | undefined;
|
|
21
|
+
isMounted(): boolean;
|
|
22
|
+
mount(parent: Element, after?: Node): void;
|
|
23
|
+
unmount(skipDOM?: boolean): void;
|
|
24
|
+
move(parent: Element, after?: Node): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
export interface Ref<T> {
|
|
7
|
+
/**
|
|
8
|
+
* Returns the currently stored value of the ref, or throws an error if no value has been set.
|
|
9
|
+
*/
|
|
10
|
+
(): T;
|
|
11
|
+
/**
|
|
12
|
+
* Stores a new value to the ref and returns that value.
|
|
13
|
+
*/
|
|
14
|
+
(value: T): T;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a Ref.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ref<T>(value?: T): Ref<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|