ilha 0.14.2 → 0.14.4
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 +3 -1
- package/dist/define.d.ts +2 -2
- package/dist/define.js +4 -4
- package/dist/index.d.ts +18 -13
- package/dist/index.js +34 -34
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.d.ts +5 -5
- package/dist/jsx-runtime.js +1 -1
- package/dist/mount-hD-OyLIo.js +1519 -0
- package/dist/types-DQVTD0ts.d.ts +41 -0
- package/dist/vnode-DHBqDHtZ.d.ts +585 -0
- package/dist/vnode-DP76Gn-b.js +89 -0
- package/package.json +3 -2
- package/dist/mount-CCMOkDSb.js +0 -1661
- package/dist/types-Cie0Ihl6.d.ts +0 -32
- package/dist/vnode-DHN2EFHi.js +0 -37
- package/dist/vnode-DyFwtMVw.d.ts +0 -20
package/README.md
CHANGED
|
@@ -55,7 +55,9 @@ import * as Atom from "effect/unstable/reactivity/Atom";
|
|
|
55
55
|
import { atom } from "ilha";
|
|
56
56
|
|
|
57
57
|
const items = atom([{ n: 1 }, { n: 2 }]);
|
|
58
|
-
const total = atom(
|
|
58
|
+
const total = atom(
|
|
59
|
+
Atom.map(items.atom, (list) => list.reduce((sum, item) => sum + item.n, 0))
|
|
60
|
+
);
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
Wrap multiple writes in `batch()`. Derived and mutation atoms use Effect's `Atom.map`, `Atom.transform`, and `Atom.fn` — pass `handle.atom`, then wrap in `atom()`. Use `watch(source, fn)` for side effects on atom changes.
|
package/dist/define.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Component } from "./types-
|
|
1
|
+
import { n as Component } from "./types-DQVTD0ts.js";
|
|
2
2
|
//#region src/define.d.ts
|
|
3
|
-
declare
|
|
3
|
+
declare const define: (name: string, component: Component) => void;
|
|
4
4
|
//#endregion
|
|
5
5
|
export { define };
|
package/dist/define.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { t as mount } from "./mount-
|
|
1
|
+
import { t as mount } from "./mount-hD-OyLIo.js";
|
|
2
2
|
|
|
3
3
|
//#region src/define.ts
|
|
4
|
-
|
|
4
|
+
const define = (name, component) => {
|
|
5
5
|
customElements.define(name, class extends HTMLElement {
|
|
6
6
|
#unmount;
|
|
7
7
|
connectedCallback() {
|
|
8
|
-
this.#unmount = mount(this, component, { hydrate: this.
|
|
8
|
+
this.#unmount = mount(this, component, { hydrate: this.matches("[data-ilha]") });
|
|
9
9
|
}
|
|
10
10
|
disconnectedCallback() {
|
|
11
11
|
this.#unmount?.();
|
|
12
12
|
this.#unmount = void 0;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
//#endregion
|
|
18
18
|
export { define };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as h } from "./vnode-
|
|
1
|
+
import { a as Instruction, c as View, i as Fragment, l as Yielded, n as Component, t as AtomHandle } from "./types-DQVTD0ts.js";
|
|
2
|
+
import { t as h } from "./vnode-DHBqDHtZ.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Stream from "effect/Stream";
|
|
5
5
|
import * as Atom from "effect/unstable/reactivity/Atom";
|
|
6
6
|
import "effect/Scope";
|
|
7
7
|
import { AtomRegistry } from "effect/unstable/reactivity/AtomRegistry";
|
|
8
8
|
//#region src/watch.d.ts
|
|
9
|
+
/** Values delivered to watch callbacks. */
|
|
10
|
+
type WatchValue = string | number | boolean | bigint | null | undefined | readonly WatchValue[] | WatchRecord;
|
|
11
|
+
interface WatchRecord {
|
|
12
|
+
readonly [key: string]: WatchValue | undefined;
|
|
13
|
+
}
|
|
9
14
|
/** Run `fn` when `source` changes — and once on mount. Sync, async, and generator components. */
|
|
10
|
-
declare
|
|
15
|
+
declare const watch: <A extends WatchValue>(source: AtomHandle<A> | Atom.Atom<A> | Stream.Stream<A, unknown, unknown>, fn: (value: A) => void) => Instruction<undefined>;
|
|
11
16
|
//#endregion
|
|
12
17
|
//#region src/atom.d.ts
|
|
13
18
|
interface AtomFn {
|
|
14
|
-
<A>(init: A | Atom.Atom<A> | Effect.Effect<A,
|
|
15
|
-
lazy<A>(init: () => A)
|
|
19
|
+
<A>(init: A | Atom.Atom<A> | Effect.Effect<A, unknown, AtomRegistry> | Stream.Stream<A, unknown, AtomRegistry>): AtomHandle<A>;
|
|
20
|
+
lazy: <A>(init: () => A) => AtomHandle<A>;
|
|
16
21
|
}
|
|
17
22
|
declare const atom: AtomFn;
|
|
18
23
|
declare const batch: (f: () => void) => void;
|
|
19
24
|
//#endregion
|
|
20
25
|
//#region src/when.d.ts
|
|
21
|
-
declare
|
|
26
|
+
declare const when: <A, E = never, R = never>(stream: Stream.Stream<A, E, R>, body: (value: A) => Generator<Yielded, View | undefined, View>) => Instruction<undefined, E>;
|
|
22
27
|
//#endregion
|
|
23
28
|
//#region src/mount.d.ts
|
|
24
|
-
|
|
29
|
+
interface RenderToStringOptions {
|
|
25
30
|
snapshot?: boolean;
|
|
26
31
|
markers?: boolean;
|
|
27
32
|
timeout?: number;
|
|
28
33
|
captureActions?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
34
|
+
}
|
|
35
|
+
interface MountOptions {
|
|
31
36
|
hydrate?: boolean;
|
|
32
|
-
onError?: (error:
|
|
33
|
-
}
|
|
34
|
-
declare
|
|
35
|
-
declare
|
|
37
|
+
onError?: <E>(error: E) => void;
|
|
38
|
+
}
|
|
39
|
+
declare const mount: (el: Element, fn: Component, opts?: MountOptions) => (() => void);
|
|
40
|
+
declare const renderToString: (fn: Component, opts?: RenderToStringOptions) => Promise<string>;
|
|
36
41
|
//#endregion
|
|
37
42
|
export { type AtomHandle, type Component, Fragment, type MountOptions, type RenderToStringOptions, type View, atom, batch, h, mount, renderToString, watch, when };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { i as Fragment, t as h } from "./vnode-
|
|
1
|
+
import { a as batch, c as isAtomHandle, d as makeFiber, i as atom, l as closeFiber, n as renderToString, o as handleOwner, r as interpret, s as instr, t as mount, u as getFiber } from "./mount-hD-OyLIo.js";
|
|
2
|
+
import { i as Fragment, t as h } from "./vnode-DP76Gn-b.js";
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import * as Stream from "effect/Stream";
|
|
5
5
|
import * as Exit from "effect/Exit";
|
|
@@ -8,7 +8,7 @@ import * as Scope from "effect/Scope";
|
|
|
8
8
|
import * as Registry from "effect/unstable/reactivity/AtomRegistry";
|
|
9
9
|
|
|
10
10
|
//#region src/watch.ts
|
|
11
|
-
|
|
11
|
+
const runStreamWatch = (fiber, effect) => {
|
|
12
12
|
const scope = Scope.forkUnsafe(fiber.scope);
|
|
13
13
|
const provided = effect.pipe(Effect.provideService(Registry.AtomRegistry, fiber.registry));
|
|
14
14
|
const fork = Effect.runFork(provided);
|
|
@@ -16,31 +16,32 @@ function runStreamWatch(fiber, effect) {
|
|
|
16
16
|
return () => {
|
|
17
17
|
Effect.runFork(Scope.close(scope, Exit.void));
|
|
18
18
|
};
|
|
19
|
-
}
|
|
20
|
-
|
|
19
|
+
};
|
|
20
|
+
const useWatchSlot = (fiber, key, mount, fn) => {
|
|
21
21
|
const i = fiber.watchI ?? 0;
|
|
22
22
|
fiber.watchI = i + 1;
|
|
23
23
|
fiber.watchSlots ??= [];
|
|
24
24
|
const existing = fiber.watchSlots[i];
|
|
25
25
|
if (existing) {
|
|
26
|
-
if (existing.key
|
|
27
|
-
existing.dispose();
|
|
28
|
-
fiber.watchSlots[i] = void 0;
|
|
29
|
-
} else {
|
|
26
|
+
if (existing.key === key) {
|
|
30
27
|
existing.fnRef.current = fn;
|
|
31
28
|
return;
|
|
32
29
|
}
|
|
30
|
+
existing.dispose();
|
|
31
|
+
fiber.watchSlots[i] = void 0;
|
|
33
32
|
}
|
|
34
33
|
const fnRef = { current: fn };
|
|
35
|
-
const unsub = mount((value) =>
|
|
34
|
+
const unsub = mount((value) => {
|
|
35
|
+
fnRef.current(value);
|
|
36
|
+
});
|
|
36
37
|
const dispose = () => unsub();
|
|
37
38
|
fiber.watchSlots[i] = {
|
|
38
|
-
|
|
39
|
+
dispose,
|
|
39
40
|
fnRef,
|
|
40
|
-
|
|
41
|
+
key
|
|
41
42
|
};
|
|
42
|
-
}
|
|
43
|
-
|
|
43
|
+
};
|
|
44
|
+
const registerWatch = (fiber, source, fn) => {
|
|
44
45
|
if (Stream.isStream(source)) {
|
|
45
46
|
useWatchSlot(fiber, source, (run) => {
|
|
46
47
|
let active = true;
|
|
@@ -56,32 +57,31 @@ function registerWatch(fiber, source, fn) {
|
|
|
56
57
|
}
|
|
57
58
|
const atom = isAtomHandle(source) ? source.atom : source;
|
|
58
59
|
useWatchSlot(fiber, atom, (run) => fiber.registry.subscribe(atom, run, { immediate: true }), fn);
|
|
59
|
-
}
|
|
60
|
+
};
|
|
60
61
|
/** Run `fn` when `source` changes — and once on mount. Sync, async, and generator components. */
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
const watch = (source, fn) => {
|
|
63
|
+
const fiber = (isAtomHandle(source) ? handleOwner.get(source) : void 0) ?? getFiber();
|
|
64
|
+
registerWatch(fiber, source, fn);
|
|
63
65
|
return instr(Effect.void);
|
|
64
|
-
}
|
|
66
|
+
};
|
|
65
67
|
|
|
66
68
|
//#endregion
|
|
67
69
|
//#region src/when.ts
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
interpret((() => body(value)), child);
|
|
82
|
-
}));
|
|
70
|
+
const when = (stream, body) => instr(Effect.gen(function* whenBody() {
|
|
71
|
+
const parent = getFiber();
|
|
72
|
+
let child;
|
|
73
|
+
parent.holes.push({ dispose() {
|
|
74
|
+
if (child) closeFiber(child);
|
|
75
|
+
child = void 0;
|
|
76
|
+
} });
|
|
77
|
+
const base = stream;
|
|
78
|
+
const src = parent.runtime.ssr ? base.pipe(Stream.take(1)) : base;
|
|
79
|
+
yield* Stream.runForEach(src, (value) => Effect.sync(() => {
|
|
80
|
+
if (child) closeFiber(child);
|
|
81
|
+
child = makeFiber(parent.runtime, parent.root, parent.paintFn, { onFail: parent.fail });
|
|
82
|
+
interpret((() => body(value)), child);
|
|
83
83
|
}));
|
|
84
|
-
}
|
|
84
|
+
}));
|
|
85
85
|
|
|
86
86
|
//#endregion
|
|
87
87
|
export { Fragment, atom, batch, h, mount, renderToString, watch, when };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as JSX } from "./vnode-
|
|
1
|
+
import { i as Fragment } from "./types-DQVTD0ts.js";
|
|
2
|
+
import { n as JSX } from "./vnode-DHBqDHtZ.js";
|
|
3
3
|
import { jsx, jsxDEV, jsxs } from "./jsx-runtime.js";
|
|
4
4
|
export { Fragment, type JSX, jsx, jsxDEV, jsxs };
|
package/dist/jsx-dev-runtime.js
CHANGED
package/dist/jsx-runtime.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as JSX, t as h } from "./vnode-
|
|
1
|
+
import { c as View, i as Fragment, o as PropBag, r as ComponentFn } from "./types-DQVTD0ts.js";
|
|
2
|
+
import { n as JSX, t as h } from "./vnode-DHBqDHtZ.js";
|
|
3
3
|
//#region src/jsx-runtime.d.ts
|
|
4
|
-
declare const jsx: (type: string |
|
|
5
|
-
declare const jsxs: (type: string |
|
|
6
|
-
declare const jsxDEV: (type: string |
|
|
4
|
+
declare const jsx: (type: string | Fragment | ComponentFn, props: PropBag | null, key?: string | number) => ReturnType<typeof h>;
|
|
5
|
+
declare const jsxs: (type: string | Fragment | ComponentFn, props: PropBag | null, key?: string | number) => ReturnType<typeof h>;
|
|
6
|
+
declare const jsxDEV: (type: string | Fragment | ComponentFn, props: PropBag | null, key?: string | number) => ReturnType<typeof h>;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { Fragment, type JSX, type View, h, jsx, jsxDEV, jsxs };
|
package/dist/jsx-runtime.js
CHANGED