@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.
- package/README.md +133 -284
- package/dist/core/context.d.ts +22 -146
- 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-BLkJ-xuh.js +242 -0
- package/dist/core-BLkJ-xuh.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/view-cBN-hn_T.js +360 -0
- package/dist/view-cBN-hn_T.js.map +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/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;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { c as e, n as t, o as n, p as r, r as i, t as a, u as o } from "./signals-CMJPGr_M.js";
|
|
2
|
+
import { a as s, b as c, c as l, d as u, f as d, g as f, i as p, l as m, m as h, n as g, o as _, s as v, t as y, u as b } from "./view-cBN-hn_T.js";
|
|
3
|
+
//#region src/core/root.ts
|
|
4
|
+
function x(t, n) {
|
|
5
|
+
let i = r(t) ? document.querySelector(t) : t;
|
|
6
|
+
e(i, "Element cannot be null.");
|
|
7
|
+
let a = h();
|
|
8
|
+
a.name = "dolla:root";
|
|
9
|
+
let s = [], u = [];
|
|
10
|
+
a[m] = i, a[l] = !!n?.debug;
|
|
11
|
+
let d = null, p = {
|
|
12
|
+
plugin: g,
|
|
13
|
+
mount: _,
|
|
14
|
+
unmount: b
|
|
15
|
+
};
|
|
16
|
+
function g(e) {
|
|
17
|
+
return s.push(e), p;
|
|
18
|
+
}
|
|
19
|
+
async function _(e) {
|
|
20
|
+
if (a.isMounted) return;
|
|
21
|
+
let t = await Promise.all(s.map((e) => e(a)));
|
|
22
|
+
for (let e of t) o(e) && u.push(e);
|
|
23
|
+
d = o(e) ? new y(a, e, {}) : v(e, a), d?.mount(i), f(a);
|
|
24
|
+
}
|
|
25
|
+
async function b() {
|
|
26
|
+
a.isMounted && (d?.unmount(!1), d = null, c(a), await Promise.all(u.map((e) => e())), u.length = 0);
|
|
27
|
+
}
|
|
28
|
+
return p;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/core/debug.ts
|
|
32
|
+
var S = () => {}, C = {
|
|
33
|
+
trace: 1,
|
|
34
|
+
info: 1,
|
|
35
|
+
log: 2,
|
|
36
|
+
warn: 3,
|
|
37
|
+
error: 4,
|
|
38
|
+
silent: 5
|
|
39
|
+
}, w = 1, T = (e) => !e.startsWith("dolla:"), E = (e) => {
|
|
40
|
+
w = C[e] || 1;
|
|
41
|
+
}, D = (e) => {
|
|
42
|
+
T = e;
|
|
43
|
+
}, O = globalThis.console || {};
|
|
44
|
+
function k(e, ...t) {
|
|
45
|
+
let n = e.name, r, i = (e, i) => {
|
|
46
|
+
if (i < w || !T(n) || !O[e]) return S;
|
|
47
|
+
if (!r) {
|
|
48
|
+
let e = "%c" + n, i = [`color:${j(n)};font-weight:bold`];
|
|
49
|
+
for (let [n, r] of t) e += `%c[${n}: %c${r}%c]`, i.push("color:#777", "color:#aaa", "color:#777");
|
|
50
|
+
r = [e, ...i];
|
|
51
|
+
}
|
|
52
|
+
return O[e].bind(O, ...r);
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
get info() {
|
|
56
|
+
return i("info", 1);
|
|
57
|
+
},
|
|
58
|
+
get trace() {
|
|
59
|
+
return i("trace", 1);
|
|
60
|
+
},
|
|
61
|
+
get log() {
|
|
62
|
+
return i("log", 2);
|
|
63
|
+
},
|
|
64
|
+
get warn() {
|
|
65
|
+
return i("warn", 3);
|
|
66
|
+
},
|
|
67
|
+
get error() {
|
|
68
|
+
return i("error", 4);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function A(e, ...t) {
|
|
73
|
+
let n = h();
|
|
74
|
+
return n.name = e, k(n, ...t);
|
|
75
|
+
}
|
|
76
|
+
function j(e) {
|
|
77
|
+
let t = 0;
|
|
78
|
+
for (let n = 0; n < e.length; n++) t = (t + e.charCodeAt(n) * 10) % 360;
|
|
79
|
+
return `oklch(0.68 0.15 ${t}deg)`;
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core/markup/nodes/portal.ts
|
|
83
|
+
var M = class extends d {
|
|
84
|
+
#e = s("");
|
|
85
|
+
#t;
|
|
86
|
+
#n;
|
|
87
|
+
#r;
|
|
88
|
+
#i;
|
|
89
|
+
constructor(e, t, n) {
|
|
90
|
+
super(), this.#t = e, this.#n = t, this.#r = n;
|
|
91
|
+
}
|
|
92
|
+
getRoot() {
|
|
93
|
+
return this.#e;
|
|
94
|
+
}
|
|
95
|
+
isMounted() {
|
|
96
|
+
return this.#e.parentNode != null;
|
|
97
|
+
}
|
|
98
|
+
mount(e, t) {
|
|
99
|
+
this.isMounted() || (g(e, this.#e, t), this.#i ||= v(this.#n, this.#t), this.#i.mount(this.#r));
|
|
100
|
+
}
|
|
101
|
+
unmount(e = !1) {
|
|
102
|
+
this.isMounted() && (e || this.#e.parentNode?.removeChild(this.#e), this.#i?.isMounted() && this.#i.unmount(!1));
|
|
103
|
+
}
|
|
104
|
+
move(e, t) {
|
|
105
|
+
_(e, this.#e, t);
|
|
106
|
+
}
|
|
107
|
+
}, N = class extends d {
|
|
108
|
+
#e = s("");
|
|
109
|
+
#t;
|
|
110
|
+
#n;
|
|
111
|
+
#r;
|
|
112
|
+
#i;
|
|
113
|
+
#a = null;
|
|
114
|
+
#o = /* @__PURE__ */ new Map();
|
|
115
|
+
constructor(e, t, n, r) {
|
|
116
|
+
super(), this.#t = e, this.#n = t, this.#r = n, this.#i = r;
|
|
117
|
+
}
|
|
118
|
+
getRoot() {
|
|
119
|
+
return this.#e;
|
|
120
|
+
}
|
|
121
|
+
isMounted() {
|
|
122
|
+
return this.#e.parentNode != null;
|
|
123
|
+
}
|
|
124
|
+
mount(e, t) {
|
|
125
|
+
this.isMounted() || (g(e, this.#e, t), this.#a = n(this.#n, (e) => {
|
|
126
|
+
u(() => {
|
|
127
|
+
this._update(Array.from(e));
|
|
128
|
+
});
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
unmount(e = !1) {
|
|
132
|
+
this.#a &&= (this.#a(), null), !e && this.isMounted() && this.#e.parentNode?.removeChild(this.#e), this._cleanup(e);
|
|
133
|
+
}
|
|
134
|
+
move(e, t) {
|
|
135
|
+
return this.mount(e, t);
|
|
136
|
+
}
|
|
137
|
+
_cleanup(e) {
|
|
138
|
+
for (let t of this.#o.values()) t._node.unmount(e);
|
|
139
|
+
this.#o.clear();
|
|
140
|
+
}
|
|
141
|
+
_update(e) {
|
|
142
|
+
if (!this.isMounted()) return;
|
|
143
|
+
if (e.length === 0) return this._cleanup(!1);
|
|
144
|
+
let t = /* @__PURE__ */ new Map();
|
|
145
|
+
a(() => {
|
|
146
|
+
let n = new Set(e.map((e, t) => this.#r(e, t)));
|
|
147
|
+
for (let [e, t] of this.#o.entries()) n.has(e) || t._node.unmount(!1);
|
|
148
|
+
for (let r = 0; r < e.length; r++) {
|
|
149
|
+
let a = e[r], o = this.#r(a, r), s = this.#o.get(o);
|
|
150
|
+
if (s && n.has(o)) s._setItem(a), s._setIndex(r);
|
|
151
|
+
else {
|
|
152
|
+
let [e, t] = i(a), [n, c] = i(r);
|
|
153
|
+
s = {
|
|
154
|
+
_key: o,
|
|
155
|
+
_node: v(this.#i(() => e(), () => n()), this.#t),
|
|
156
|
+
_item: e,
|
|
157
|
+
_setItem: t,
|
|
158
|
+
_index: n,
|
|
159
|
+
_setIndex: c
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
t.set(o, s);
|
|
163
|
+
}
|
|
164
|
+
}), this.#o = t;
|
|
165
|
+
let n = this.#e.parentElement, r = this.#e;
|
|
166
|
+
for (let e of this.#o.values()) {
|
|
167
|
+
let t = r.nextSibling;
|
|
168
|
+
e._node.isMounted() ? e._node.getRoot() !== t && e._node.move(n, r) : e._node.mount(n, r), r = e._node.getRoot();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/core/markup/helpers.ts
|
|
174
|
+
function P(e, t, n) {
|
|
175
|
+
return o(e) ? p(N, { args: [
|
|
176
|
+
e,
|
|
177
|
+
t,
|
|
178
|
+
n
|
|
179
|
+
] }) : Array.from(e).map((e, t) => n(() => e, () => t));
|
|
180
|
+
}
|
|
181
|
+
function F(e, n, r) {
|
|
182
|
+
return o(e) ? p(b, { args: [t(() => e() ? n : r)] }) : e ? n : r;
|
|
183
|
+
}
|
|
184
|
+
function I(e, t, n) {
|
|
185
|
+
return F(e, t, n);
|
|
186
|
+
}
|
|
187
|
+
function L(e, t, n) {
|
|
188
|
+
return F(e, n, t);
|
|
189
|
+
}
|
|
190
|
+
function R(e, t) {
|
|
191
|
+
return p(M, { args: [t, e] });
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/core/markup/html.ts
|
|
195
|
+
var z = /* @__PURE__ */ function(e) {
|
|
196
|
+
return e[e.Slash = 0] = "Slash", e[e.Text = 1] = "Text", e[e.Whitespace = 2] = "Whitespace", e[e.TagName = 3] = "TagName", e[e.Comment = 4] = "Comment", e[e.PropSet = 5] = "PropSet", e[e.PropAppend = 6] = "PropAppend", e;
|
|
197
|
+
}(z || {});
|
|
198
|
+
function B(e, ...t) {
|
|
199
|
+
let n = [e, ...t], r = z.Text, i = "", a = "", o = [0], s = "", c = (e) => {
|
|
200
|
+
r === z.Text && (e || (i = i.replace(/^\s*\n\s*|\s*\n\s*$/g, ""))) ? o.push(e ? n[e] : i) : r === z.TagName && (e || i) ? (o[1] = e ? n[e] : i, r = z.Whitespace) : r === z.Whitespace && i === "..." && e ? o[2] = Object.assign(o[2] || {}, n[e]) : r === z.Whitespace && i && !e ? (o[2] = o[2] || {})[i] = !0 : r >= z.PropSet && (r === z.PropSet ? ((o[2] = o[2] || {})[s] = e ? i ? i + n[e] : n[e] : i, r = z.PropAppend) : (e || i) && (o[2][s] += e ? i + n[e] : i)), i = "";
|
|
201
|
+
};
|
|
202
|
+
for (let t = 0; t < e.length; t++) {
|
|
203
|
+
t && (r === z.Text && c(), c(t));
|
|
204
|
+
for (let n = 0; n < e[t].length; n++) {
|
|
205
|
+
let l = e[t][n];
|
|
206
|
+
if (r === z.Text) l === "<" ? (c(), o = [
|
|
207
|
+
o,
|
|
208
|
+
"",
|
|
209
|
+
null
|
|
210
|
+
], r = z.TagName) : i += l;
|
|
211
|
+
else if (r === z.Comment) i === "--" && l === ">" ? (r = z.Text, i = "") : i = l + i[0];
|
|
212
|
+
else if (a) l === a ? a = "" : i += l;
|
|
213
|
+
else if (l === "\"" || l === "'") a = l;
|
|
214
|
+
else if (l === ">") c(), r = z.Text;
|
|
215
|
+
else if (r) if (l === "=") r = z.PropSet, s = i, i = "";
|
|
216
|
+
else if (l === "/" && (r < z.PropSet || e[t][n + 1] === ">")) {
|
|
217
|
+
c(), r === z.TagName && (o = o[0]);
|
|
218
|
+
let e = o;
|
|
219
|
+
o = o[0];
|
|
220
|
+
let t = e[1], n = e[2] || {}, i = e.slice(3);
|
|
221
|
+
o.push(p(t, {
|
|
222
|
+
...n,
|
|
223
|
+
children: i
|
|
224
|
+
})), r = z.Slash;
|
|
225
|
+
} else l === " " || l === " " || l === "\n" || l === "\r" ? (c(), r = z.Whitespace) : i += l;
|
|
226
|
+
r === z.TagName && i === "!--" && (r = z.Comment, o = o[0]);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return c(), o.length > 2 ? o.slice(1) : o[1];
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region src/core/ref.ts
|
|
233
|
+
function V() {
|
|
234
|
+
let e;
|
|
235
|
+
return ((...t) => t.length ? (e = t[0], () => {
|
|
236
|
+
e = void 0;
|
|
237
|
+
}) : e);
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
export { L as a, k as c, x as d, P as i, D as l, B as n, I as o, R as r, A as s, V as t, E as u };
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=core-BLkJ-xuh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-BLkJ-xuh.js","names":["#context","#value","#parent","#anchor","#childNode","#context","#items","#key","#render","#root","#unsubscribe","#connectedItems"],"sources":["../src/core/root.ts","../src/core/debug.ts","../src/core/markup/nodes/portal.ts","../src/core/markup/nodes/repeat.ts","../src/core/markup/helpers.ts","../src/core/markup/html.ts","../src/core/ref.ts"],"sourcesContent":["import type { Renderable, View } from \"../types.js\";\nimport { assert, isFunction, isString } from \"../utils.js\";\nimport { type Context, createContext, mountContext, unmountContext } from \"./context.js\";\nimport { ViewNode } from \"./markup/nodes/view.js\";\nimport { type MarkupNode } from \"./markup/types.js\";\nimport { render } from \"./markup/utils.js\";\nimport { DEBUG, PARENT_ELEMENT } from \"./symbols.js\";\n\nexport type CleanupCallback = () => void | Promise<void>;\n\n/**\n * Plugins run before the app is mounted. If they return a promise, mounting will be delayed until the promise resolves.\n * If a cleanup function is returned, it will be called before the app is unmounted. The cleanup function's promise will delay unmounting.\n *\n * Hooks can be used inside plugins.\n */\nexport type DollaPlugin = (context: Context) => Promise<CleanupCallback | void> | CleanupCallback | void;\n\nexport interface DollaRootOptions {\n /**\n * Adds additional view info to the DOM to help with debugging.\n */\n debug?: boolean;\n}\n\nexport interface DollaRoot {\n /**\n * Registers a plugin to be added before `mount`.\n */\n plugin(plugin: DollaPlugin): DollaRoot;\n\n /**\n * Mounts a `view` to this root.\n */\n mount(view: View<{}>): Promise<void>;\n\n /**\n * Mounts any renderable content to this root.\n */\n mount(content: Renderable): Promise<void>;\n\n /**\n * Unmounts the currently mounted content.\n */\n unmount(): void;\n}\n\nexport function createRoot(selector: string, options?: DollaRootOptions): DollaRoot;\nexport function createRoot(element: Element, options?: DollaRootOptions): DollaRoot;\nexport function createRoot(target: string | Element, options?: DollaRootOptions) {\n const element = isString(target) ? document.querySelector(target) : target;\n assert(element, \"Element cannot be null.\");\n\n const context = createContext();\n context.name = \"dolla:root\";\n\n const plugins: DollaPlugin[] = [];\n const cleanup: CleanupCallback[] = [];\n\n context[PARENT_ELEMENT] = element;\n context[DEBUG] = Boolean(options?.debug);\n\n let rootNode: MarkupNode | null = null;\n\n const self: DollaRoot = { plugin, mount, unmount };\n\n function plugin(plugin: DollaPlugin) {\n plugins.push(plugin);\n return self;\n }\n\n async function mount(content: View<{}> | Renderable) {\n if (context.isMounted) return;\n\n const results = await Promise.all(plugins.map((fn) => fn(context)));\n for (const result of results) {\n if (isFunction<CleanupCallback>(result)) {\n cleanup.push(result);\n }\n }\n\n rootNode = isFunction<View<{}>>(content) ? new ViewNode(context, content, {}) : render(content, context);\n rootNode?.mount(element!);\n\n mountContext(context);\n }\n\n async function unmount() {\n if (!context.isMounted) return;\n\n rootNode?.unmount(false);\n rootNode = null;\n\n unmountContext(context);\n\n await Promise.all(cleanup.map((callback) => callback()));\n cleanup.length = 0;\n }\n\n return self;\n}\n","import { Context, createContext } from \"./context.js\";\n\nexport const noOp = () => {};\n\nexport type LogLevel = \"info\" | \"log\" | \"warn\" | \"error\" | \"silent\";\nconst LEVELS: Record<string, number> = { trace: 1, info: 1, log: 2, warn: 3, error: 4, silent: 5 };\n\nlet logLevel = 1;\nlet logFilter = (name: string) => !name.startsWith(\"dolla:\");\n\n// 3. Extracted configuration setters (replacing static class methods)\nexport const setLogLevel = (level: LogLevel) => {\n logLevel = LEVELS[level] || 1;\n};\nexport const setLogFilter = (filter: (name: string) => boolean) => {\n logFilter = filter;\n};\n\nconst c: any = globalThis.console || {};\n\nexport function getDebug(context: Context, ...tags: [string, any][]) {\n const name = context.name;\n let args: any[];\n\n const make = (method: string, level: number): ((...args: any[]) => void) => {\n if (level < logLevel || !logFilter(name) || !c[method]) return noOp;\n\n // Build and cache the console arguments on the first valid log\n if (!args) {\n let p = \"%c\" + name;\n let s = [`color:${okhash(name)};font-weight:bold`];\n for (const [k, v] of tags) {\n p += `%c[${k}: %c${v}%c]`;\n s.push(\"color:#777\", \"color:#aaa\", \"color:#777\");\n }\n args = [p, ...s];\n }\n\n return c[method].bind(c, ...args);\n };\n\n return {\n get info() {\n return make(\"info\", 1);\n },\n get trace() {\n return make(\"trace\", 1);\n },\n get log() {\n return make(\"log\", 2);\n },\n get warn() {\n return make(\"warn\", 3);\n },\n get error() {\n return make(\"error\", 4);\n },\n };\n}\n\nexport function createDebug(name: string, ...tags: [string, any][]) {\n const context = createContext();\n context.name = name;\n return getDebug(context, ...tags);\n}\n\n/**\n * Takes any string and returns an OKLCH color.\n */\nfunction okhash(value: string) {\n let hue = 0;\n for (let i = 0; i < value.length; i++) {\n hue = (hue + value.charCodeAt(i) * 10) % 360;\n }\n return `oklch(0.68 0.15 ${hue}deg)`;\n}\n","import type { Renderable } from \"../../../types.js\";\nimport { Context } from \"../../context.js\";\nimport { MarkupNode, MountTarget } from \"../types.js\";\nimport { addChild, createTextNode, moveAfter, render } from \"../utils.js\";\n\n/**\n * Renders content into a specified parent node.\n */\nexport class PortalNode extends MarkupNode {\n // Acts as a physical placeholder in the logical DOM tree\n #anchor = createTextNode(\"\");\n\n #context: Context;\n #value: Renderable;\n #parent: MountTarget;\n #childNode?: MarkupNode;\n\n constructor(context: Context, value: Renderable, parent: MountTarget) {\n super();\n this.#context = context;\n this.#value = value;\n this.#parent = parent;\n }\n\n override getRoot() {\n // Return the anchor, allowing siblings to mount correctly around it\n return this.#anchor;\n }\n\n override isMounted() {\n return this.#anchor.parentNode != null;\n }\n\n override mount(logicalParent: MountTarget, after?: Node) {\n if (!this.isMounted()) {\n // Mount the anchor in the standard document flow\n addChild(logicalParent, this.#anchor, after);\n\n // Render the content and mount it to the portal target\n if (!this.#childNode) {\n this.#childNode = render(this.#value, this.#context);\n }\n this.#childNode.mount(this.#parent);\n }\n }\n\n override unmount(skipDOM = false) {\n if (this.isMounted()) {\n if (!skipDOM) {\n this.#anchor.parentNode?.removeChild(this.#anchor);\n }\n\n // Portals always force unmount the DOM of their children\n if (this.#childNode?.isMounted()) {\n this.#childNode.unmount(false);\n }\n }\n }\n\n override move(logicalParent: MountTarget, after?: Node) {\n moveAfter(logicalParent, this.#anchor, after);\n }\n}\n","import type { Renderable } from \"../../../types.js\";\nimport type { Context } from \"../../context.js\";\nimport { batch, type Getter, createAtom, subscribe, type Setter } from \"../../signals.js\";\nimport { scheduleUpdate } from \"../scheduler.js\";\nimport { MarkupNode } from \"../types.js\";\nimport { addChild, createTextNode, render } from \"../utils.js\";\n\n// ----- Types ----- //\n\nexport type Key = any;\n\nexport type KeyFn<T> = (item: T, index: number) => Key;\nexport type RenderFn<T> = (item: Getter<T>, index: Getter<number>) => Renderable;\n\ntype ConnectedItem<T> = {\n _key: Key;\n _item: Getter<T>;\n _setItem: Setter<T>;\n _index: Getter<number>;\n _setIndex: Setter<number>;\n _node: MarkupNode;\n};\n\n// ----- Code ----- //\n\n/**\n * Renders a list of items.\n */\nexport class RepeatNode<T> extends MarkupNode {\n #root = createTextNode(\"\");\n\n #context;\n\n #items: Getter<Iterable<T>>;\n #key: KeyFn<T>;\n #render: RenderFn<T>;\n\n #unsubscribe: (() => void) | null = null;\n #connectedItems: Map<Key, ConnectedItem<T>> = new Map();\n\n constructor(context: Context, items: Getter<Iterable<T>>, key: KeyFn<T>, render: RenderFn<T>) {\n super();\n this.#context = context;\n\n this.#items = items;\n this.#key = key;\n this.#render = render;\n }\n\n override getRoot() {\n return this.#root;\n }\n\n override isMounted() {\n return this.#root.parentNode != null;\n }\n\n override mount(parent: Element, after?: Node) {\n if (!this.isMounted()) {\n addChild(parent, this.#root, after);\n\n this.#unsubscribe = subscribe(this.#items, (items) => {\n scheduleUpdate(() => {\n this._update(Array.from(items));\n });\n });\n }\n }\n\n override unmount(skipDOM = false) {\n if (this.#unsubscribe) {\n this.#unsubscribe();\n this.#unsubscribe = null;\n }\n\n if (!skipDOM && this.isMounted()) {\n this.#root.parentNode?.removeChild(this.#root);\n }\n\n this._cleanup(skipDOM);\n }\n\n override move(parent: Element, after?: Node) {\n // TODO: Implement move\n return this.mount(parent, after);\n }\n\n private _cleanup(skipDOM: boolean) {\n for (const item of this.#connectedItems.values()) {\n item._node.unmount(skipDOM);\n }\n this.#connectedItems.clear();\n }\n\n private _update(value: T[]) {\n if (!this.isMounted()) return;\n\n if (value.length === 0) {\n return this._cleanup(false);\n }\n\n const nextItems = new Map<Key, ConnectedItem<T>>();\n\n batch(() => {\n // Track keys for the incoming list\n const nextKeys = new Set(value.map((item, index) => this.#key(item, index)));\n\n // Unmount deleted items immediately.\n // This collapses the DOM tree so surviving items sit adjacent to each other.\n for (const [key, connected] of this.#connectedItems.entries()) {\n if (!nextKeys.has(key)) {\n connected._node.unmount(false);\n }\n }\n\n // Prepare state and allocate new nodes.\n for (let i = 0; i < value.length; i++) {\n const itemVal = value[i];\n const key = this.#key(itemVal, i);\n let connected = this.#connectedItems.get(key);\n\n if (connected && nextKeys.has(key)) {\n connected._setItem(itemVal);\n connected._setIndex(i);\n } else {\n const [_item, _setItem] = createAtom(itemVal);\n const [_index, _setIndex] = createAtom(i);\n\n const renderContent = this.#render(\n () => _item(),\n () => _index(),\n );\n const _node = render(renderContent, this.#context);\n\n connected = {\n _key: key,\n _node,\n _item,\n _setItem,\n _index,\n _setIndex,\n };\n }\n nextItems.set(key, connected);\n }\n });\n\n this.#connectedItems = nextItems;\n\n // Forward pass to insert or move nodes.\n const parent = this.#root.parentElement!;\n let referenceNode: Node = this.#root;\n\n for (const connected of this.#connectedItems.values()) {\n const expectedNext = referenceNode.nextSibling;\n\n if (!connected._node.isMounted()) {\n // Node is new. Mount it exactly at the current cursor.\n connected._node.mount(parent, referenceNode);\n } else if (connected._node.getRoot() !== expectedNext) {\n // Node is out of order. Move it.\n connected._node.move(parent, referenceNode);\n }\n\n // Advance the cursor.\n referenceNode = connected._node.getRoot()!;\n }\n }\n}\n","import { createMarkup, Renderable } from \"..\";\nimport { isFunction } from \"../../utils\";\nimport { type Getter, compose } from \"../signals\";\nimport { DynamicNode } from \"./nodes/dynamic\";\nimport { PortalNode } from \"./nodes/portal\";\nimport { KeyFn, RenderFn, RepeatNode } from \"./nodes/repeat\";\n\n/**\n * Displays a dynamic list. Items will be added and removed as the list is updated.\n *\n * @param items - List items. Can be reactive.\n * @param keyFn - Takes (item, index) as plain values and returns a unique key to identify that item (usually the item's ID).\n * @param renderFn - Takes (item, index) as Reactive values and returns content to display for that item.\n */\nexport function forEach<T>(\n items: Getter<Iterable<T>> | Iterable<T>,\n keyFn: KeyFn<T>,\n renderFn: RenderFn<T>,\n): Renderable {\n if (isFunction(items)) {\n return createMarkup(RepeatNode<T>, { args: [items, keyFn, renderFn] });\n } else {\n return Array.from(items).map((item, index) =>\n renderFn(\n () => item,\n () => index,\n ),\n );\n }\n}\n\n/**\n * Displays content conditionally. When `condition` is truthy, display `content`. When `condition` is falsy, display `fallback`.\n *\n * @param condition - Condition to hide or show content on. Can be reactive.\n * @param whenTruthy - Content to display when condition is truthy.\n * @param whenFalsy - Content to display when condition is falsy.\n */\nfunction _conditional(condition: any, whenTruthy?: Renderable, whenFalsy?: Renderable): Renderable {\n if (isFunction(condition)) {\n return createMarkup(DynamicNode, {\n args: [compose(() => (condition() ? whenTruthy : whenFalsy))],\n });\n } else if (condition) {\n return whenTruthy;\n } else {\n return whenFalsy;\n }\n}\n\n/**\n * Shows content only when `condition` is truthy.\n * It can be a plain value or a Getter to track dynamically.\n *\n * @param condition - Condition to hide or show content on.\n * @param content - Content to display when condition is truthy.\n * @param fallback - Content to display when condition is falsy.\n */\nexport function showIf(condition: any, content: Renderable, fallback?: Renderable): Renderable {\n return _conditional(condition, content, fallback);\n}\n\n/**\n * Shows content only when `condition` is falsy.\n * It can be a plain value or a Getter to track dynamically.\n *\n * @param condition - Condition to hide or show content on.\n * @param content - Content to display when condition is falsy.\n * @param fallback - Content to display when condition is truthy.\n */\nexport function hideIf(condition: any, content: Renderable, fallback?: Renderable): Renderable {\n return _conditional(condition, fallback, content);\n}\n\n/**\n * Creates a portal that renders `content` into another element on the page.\n **/\nexport function createPortal(parent: Element, content: Renderable) {\n return createMarkup(PortalNode, { args: [content, parent] });\n}\n","// This file is a heavily modified version of the 'htm' library.\n// Original source: https://github.com/developit/htm\n//\n// --- Original htm License ---\n// Copyright 2018 Jason Miller\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport type { Markup } from \"./types.js\";\nimport { createMarkup } from \"./utils.js\";\n\nexport type Template = Markup | Markup[];\n\nconst enum Mode {\n Slash = 0,\n Text = 1,\n Whitespace = 2,\n TagName = 3,\n Comment = 4,\n PropSet = 5,\n PropAppend = 6,\n}\n\nexport function html(statics: TemplateStringsArray, ...args: any[]): Template {\n const fields = [statics, ...args];\n\n let mode = Mode.Text;\n let buffer = \"\";\n let quote = \"\";\n let current: any[] = [0];\n let propName = \"\";\n\n const commit = (field?: number) => {\n if (mode === Mode.Text && (field || (buffer = buffer.replace(/^\\s*\\n\\s*|\\s*\\n\\s*$/g, \"\")))) {\n current.push(field ? fields[field] : buffer);\n } else if (mode === Mode.TagName && (field || buffer)) {\n current[1] = field ? fields[field] : buffer;\n mode = Mode.Whitespace;\n } else if (mode === Mode.Whitespace && buffer === \"...\" && field) {\n current[2] = Object.assign(current[2] || {}, fields[field]);\n } else if (mode === Mode.Whitespace && buffer && !field) {\n (current[2] = current[2] || {})[buffer] = true;\n } else if (mode >= Mode.PropSet) {\n if (mode === Mode.PropSet) {\n (current[2] = current[2] || {})[propName] = field ? (buffer ? buffer + fields[field] : fields[field]) : buffer;\n mode = Mode.PropAppend;\n } else if (field || buffer) {\n current[2][propName] += field ? buffer + fields[field] : buffer;\n }\n }\n\n buffer = \"\";\n };\n\n for (let i = 0; i < statics.length; i++) {\n if (i) {\n if (mode === Mode.Text) commit();\n commit(i);\n }\n\n for (let j = 0; j < statics[i].length; j++) {\n const char = statics[i][j];\n\n if (mode === Mode.Text) {\n if (char === \"<\") {\n // commit buffer\n commit();\n current = [current, \"\", null];\n mode = Mode.TagName;\n } else {\n buffer += char;\n }\n } else if (mode === Mode.Comment) {\n // Ignore everything until the last three characters are '-', '-' and '>'\n if (buffer === \"--\" && char === \">\") {\n mode = Mode.Text;\n buffer = \"\";\n } else {\n buffer = char + buffer[0];\n }\n } else if (quote) {\n if (char === quote) {\n quote = \"\";\n } else {\n buffer += char;\n }\n } else if (char === '\"' || char === \"'\") {\n quote = char;\n } else if (char === \">\") {\n commit();\n mode = Mode.Text;\n } else if (!mode) {\n // Ignore everything until the tag ends\n } else if (char === \"=\") {\n mode = Mode.PropSet;\n propName = buffer;\n buffer = \"\";\n } else if (char === \"/\" && (mode < Mode.PropSet || statics[i][j + 1] === \">\")) {\n commit();\n if (mode === Mode.TagName) {\n current = current[0];\n }\n const node = current;\n current = current[0];\n\n const type = node[1];\n const props = node[2] || {};\n const children = node.slice(3);\n\n current.push(createMarkup(type, { ...props, children }));\n\n mode = Mode.Slash;\n } else if (char === \" \" || char === \"\\t\" || char === \"\\n\" || char === \"\\r\") {\n // <a disabled>\n commit();\n mode = Mode.Whitespace;\n } else {\n buffer += char;\n }\n\n if (mode === Mode.TagName && buffer === \"!--\") {\n mode = Mode.Comment;\n current = current[0];\n }\n }\n }\n commit();\n\n return current.length > 2 ? current.slice(1) : current[1];\n}\n","import { assert } from \"../utils\";\n\nexport interface Ref<T> {\n /**\n * Call with no arguments to get the stored value.\n * Throws an error if the ref is empty (this means you forgot to pass it or it was called after teardown).\n */\n (): T;\n\n /**\n * Call with an argument to initialize the value. Returns a cleanup function.\n * The cleanup function should clear any references to the DOM node.\n */\n (value: T): () => void;\n}\n\nexport function createRef<T = HTMLElement>(): Ref<T> {\n let currentValue: T | undefined;\n\n return ((...args: [T]) => {\n if (args.length) {\n currentValue = args[0];\n return () => {\n currentValue = undefined;\n };\n } else {\n // assert(currentValue !== undefined, \"Empty ref!\");\n return currentValue;\n }\n }) as Ref<T>;\n}\n"],"mappings":";;;AAiDA,SAAgB,EAAW,GAA0B,GAA4B;CAC/E,IAAM,IAAU,EAAS,EAAO,GAAG,SAAS,cAAc,EAAO,GAAG;AACpE,GAAO,GAAS,0BAA0B;CAE1C,IAAM,IAAU,GAAe;AAC/B,GAAQ,OAAO;CAEf,IAAM,IAAyB,EAAE,EAC3B,IAA6B,EAAE;AAGrC,CADA,EAAQ,KAAkB,GAC1B,EAAQ,KAAS,EAAQ,GAAS;CAElC,IAAI,IAA8B,MAE5B,IAAkB;EAAE;EAAQ;EAAO;EAAS;CAElD,SAAS,EAAO,GAAqB;AAEnC,SADA,EAAQ,KAAK,EAAO,EACb;;CAGT,eAAe,EAAM,GAAgC;AACnD,MAAI,EAAQ,UAAW;EAEvB,IAAM,IAAU,MAAM,QAAQ,IAAI,EAAQ,KAAK,MAAO,EAAG,EAAQ,CAAC,CAAC;AACnE,OAAK,I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,GAAG,EAAQ;;;;ACtHzD,SAAgB,IAAqC;CACnD,IAAI;AAEJ,UAAS,GAAG,MACN,EAAK,UACP,IAAe,EAAK,UACP;AACX,MAAe,KAAA;MAIV"}
|
package/dist/http/index.d.ts
CHANGED
|
@@ -1,45 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* so it's the perfect way to handle things like auth headers and permission checks for API calls.
|
|
4
|
-
*/
|
|
5
|
-
export declare class HTTP {
|
|
6
|
-
#private;
|
|
7
|
-
/**
|
|
8
|
-
* Adds a new middleware that will apply to subsequent requests.
|
|
9
|
-
* Returns a function to remove this middleware.
|
|
10
|
-
*
|
|
11
|
-
* @param middleware - A middleware function that will intercept requests.
|
|
12
|
-
*/
|
|
13
|
-
use(fn: HTTPMiddleware): () => void;
|
|
14
|
-
get<ResBody = unknown>(uri: string, options?: RequestOptions<never>): Promise<HTTPResponse<ResBody>>;
|
|
15
|
-
put<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
16
|
-
patch<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
17
|
-
post<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
18
|
-
delete<ResBody = unknown>(uri: string, options?: RequestOptions<never>): Promise<HTTPResponse<ResBody>>;
|
|
19
|
-
head<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
20
|
-
options<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
21
|
-
trace<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody>): Promise<HTTPResponse<ResBody>>;
|
|
22
|
-
}
|
|
23
|
-
export type HTTPMiddleware = (request: HTTPRequest<unknown>, next: () => Promise<HTTPResponse<unknown>>) => void | Promise<void>;
|
|
24
|
-
export interface RequestOptions<ReqBody> {
|
|
25
|
-
/**
|
|
26
|
-
* Body to send with the request.
|
|
27
|
-
*/
|
|
1
|
+
export type HTTPMiddleware = (request: HTTPRequest<unknown>, next: () => Promise<HTTPResponse<unknown>>) => Promise<HTTPResponse<unknown> | void> | void;
|
|
2
|
+
export interface RequestOptions<ReqBody, ResBody> {
|
|
28
3
|
body?: ReqBody;
|
|
29
|
-
/**
|
|
30
|
-
* Headers to send with the request.
|
|
31
|
-
*/
|
|
32
4
|
headers?: Record<string, any> | Headers;
|
|
33
|
-
/**
|
|
34
|
-
* Query params to interpolate into the URL.
|
|
35
|
-
*/
|
|
36
5
|
query?: Record<string, any> | URLSearchParams;
|
|
6
|
+
parse?: (response: Response) => Promise<ResBody>;
|
|
7
|
+
signal?: AbortSignal;
|
|
37
8
|
}
|
|
38
9
|
export interface HTTPRequest<Body> {
|
|
39
10
|
method: string;
|
|
40
11
|
url: URL;
|
|
41
12
|
headers: Headers;
|
|
42
13
|
body: Body;
|
|
14
|
+
signal?: AbortSignal;
|
|
43
15
|
}
|
|
44
16
|
export interface HTTPResponse<Body> {
|
|
45
17
|
method: string;
|
|
@@ -53,3 +25,19 @@ export declare class HTTPResponseError extends Error {
|
|
|
53
25
|
response: HTTPResponse<any>;
|
|
54
26
|
constructor(response: HTTPResponse<any>);
|
|
55
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* A simple HTTP client with middleware support.
|
|
30
|
+
*/
|
|
31
|
+
export declare class HTTP {
|
|
32
|
+
#private;
|
|
33
|
+
constructor();
|
|
34
|
+
use(fn: HTTPMiddleware): () => void;
|
|
35
|
+
get<ResBody = unknown>(uri: string, options?: RequestOptions<never, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
36
|
+
put<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
37
|
+
patch<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
38
|
+
post<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
39
|
+
delete<ResBody = unknown>(uri: string, options?: RequestOptions<never, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
40
|
+
head<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
41
|
+
options<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
42
|
+
trace<ResBody = unknown, ReqBody = unknown>(uri: string, options?: RequestOptions<ReqBody, ResBody>): Promise<HTTPResponse<ResBody>>;
|
|
43
|
+
}
|