effect-ui-react 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +305 -2
  3. package/dist/Intrinsics.d.ts +16 -0
  4. package/dist/Intrinsics.js +1 -0
  5. package/dist/React.d.ts +58 -0
  6. package/dist/React.js +55 -0
  7. package/dist/ReactHost.d.ts +115 -0
  8. package/dist/ReactHost.js +750 -0
  9. package/dist/ReactRefs.d.ts +16 -0
  10. package/dist/ReactRefs.js +23 -0
  11. package/dist/dom/ReactDomCommand.d.ts +83 -0
  12. package/dist/dom/ReactDomCommand.js +86 -0
  13. package/dist/dom/ReactDomFiles.d.ts +1 -0
  14. package/dist/dom/ReactDomFiles.js +1 -0
  15. package/dist/dom/ReactDomHead.d.ts +1 -0
  16. package/dist/dom/ReactDomHead.js +1 -0
  17. package/dist/dom/ReactDomHost.d.ts +60 -0
  18. package/dist/dom/ReactDomHost.js +186 -0
  19. package/dist/dom/ReactDomImages.d.ts +1 -0
  20. package/dist/dom/ReactDomImages.js +1 -0
  21. package/dist/dom/ReactDomKeyboard.d.ts +1 -0
  22. package/dist/dom/ReactDomKeyboard.js +1 -0
  23. package/dist/dom/ReactDomRouter.d.ts +1 -0
  24. package/dist/dom/ReactDomRouter.js +1 -0
  25. package/dist/dom/ReactDomScheduler.d.ts +1 -0
  26. package/dist/dom/ReactDomScheduler.js +1 -0
  27. package/dist/dom/ReactDomSubscription.d.ts +1 -0
  28. package/dist/dom/ReactDomSubscription.js +1 -0
  29. package/dist/dom/index.d.ts +10 -0
  30. package/dist/dom/index.js +10 -0
  31. package/dist/dom/intrinsics.d.ts +21 -0
  32. package/dist/dom/intrinsics.js +1 -0
  33. package/dist/dom/server/ReactDomServer.d.ts +11 -0
  34. package/dist/dom/server/ReactDomServer.js +16 -0
  35. package/dist/dom/server/index.d.ts +1 -0
  36. package/dist/dom/server/index.js +1 -0
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.js +3 -0
  39. package/dist/internal/child-placement.d.ts +49 -0
  40. package/dist/internal/child-placement.js +136 -0
  41. package/dist/internal/react-component-bridge.d.ts +133 -0
  42. package/dist/internal/react-component-bridge.js +220 -0
  43. package/dist/internal/react-element.d.ts +138 -0
  44. package/dist/internal/react-element.js +261 -0
  45. package/dist/internal/render-view.d.ts +24 -0
  46. package/dist/internal/render-view.js +110 -0
  47. package/dist/internal/to-react-element.d.ts +20 -0
  48. package/dist/internal/to-react-element.js +135 -0
  49. package/dist/internal/wrap-helper.d.ts +9 -0
  50. package/dist/internal/wrap-helper.js +31 -0
  51. package/package.json +78 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nick Breaton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,306 @@
1
- # Temporary Holding Version
1
+ # effect-ui-react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A React host for [Effect UI](https://ui.effect.website/). Write Effect UI, render React.
4
+
5
+ Take full advantage of the React ecosystem without your agents tripping over the rules and idiosyncrasies of hooks on every prompt.
6
+
7
+ **Note: This library is still experimental.**
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ npm install effect-ui-react effect@~4.2.0 react@^19.3.0
13
+ # Browser rendering and SSR also require React DOM:
14
+ npm install react-dom@^19.3.0
15
+ ```
16
+
17
+ React and Effect are peer dependencies. React DOM is an optional peer, needed only
18
+ for `effect-ui-react/dom` and `effect-ui-react/dom/server`.
19
+
20
+ ## Usage
21
+
22
+ Build components similar to Effect UI HTML, but targeting a React virtual DOM instead:
23
+
24
+ ```ts
25
+ import { Effect, Layer, Schema } from "effect"
26
+ import { React } from "effect-ui-react"
27
+ import { ReactDomHost } from "effect-ui-react/dom"
28
+
29
+ const App = React.component({
30
+ name: "App",
31
+ model: Schema.Null,
32
+ message: Schema.Never
33
+ }).make({
34
+ init: () => null,
35
+ update: ($) => $.model,
36
+ view: (h) => h.h1.children("Hello, world!")
37
+ })
38
+
39
+ ReactDomHost.mount(App, {}, document.getElementById("root")!).pipe(
40
+ Layer.launch,
41
+ Effect.runFork
42
+ )
43
+ ```
44
+
45
+ ### Rendering a React component
46
+
47
+ Pass an imported React component to `h.el`, such as Base UI's `Button`:
48
+
49
+ ```ts
50
+ import { Button } from "@base-ui/react/button"
51
+ import { Effect, Layer, Schema } from "effect"
52
+ import { React } from "effect-ui-react"
53
+ import { ReactDomHost } from "effect-ui-react/dom"
54
+
55
+ const App = React.component({
56
+ name: "App",
57
+ model: Schema.Null,
58
+ message: Schema.Never
59
+ }).make({
60
+ init: () => null,
61
+ update: ($) => $.model,
62
+ view: (h) => h.el(Button).children("Hello, world!")
63
+ })
64
+ ```
65
+
66
+ ### Sending Messages
67
+
68
+ Since React components do not differentiate props from events, the `h.event` adapter can be used to send messages:
69
+
70
+ ```ts
71
+ import { Schema } from "effect"
72
+ import { UiSchema } from "effect/ui"
73
+ import { React } from "effect-ui-react"
74
+
75
+ const Message = UiSchema.TaggedEnum({
76
+ ClickedIncrement: {}
77
+ })
78
+
79
+ export const Counter = React.component({
80
+ name: "Counter",
81
+ model: Schema.Number,
82
+ message: Message
83
+ }).make({
84
+ init: () => 0,
85
+ update: {
86
+ ClickedIncrement: ($) => $.model + 1
87
+ },
88
+ view: (h, count) =>
89
+ h.button
90
+ .props({ onClick: h.event(Message.ClickedIncrement()) })
91
+ .children(`Count: ${count}`)
92
+ })
93
+ ```
94
+
95
+ ### Component Composition
96
+
97
+ Effect UI component composition works as normal. The counter above can be included in a parent component:
98
+
99
+ ```ts
100
+ import { Schema } from "effect"
101
+ import { React } from "effect-ui-react"
102
+ import { Counter } from "./Counter"
103
+
104
+ const App = React.component({
105
+ name: "App",
106
+ model: Schema.Null,
107
+ message: Schema.Never
108
+ }).make({
109
+ init: () => null,
110
+ update: ($) => $.model,
111
+ view: (h) => h.div.children(Counter(h, {}))
112
+ })
113
+ ```
114
+
115
+ However, it's common within the React ecosystem for components to expose additional targets via [render props](https://react.dev/reference/react/cloneElement#passing-data-with-a-render-prop). The `h.render` helper can bridge that into Effect UI:
116
+
117
+ ```ts
118
+ import { Button } from "@base-ui/react/button"
119
+ import { Schema } from "effect"
120
+ import { React } from "effect-ui-react"
121
+
122
+ const App = React.component({
123
+ name: "App",
124
+ model: Schema.Null,
125
+ message: Schema.Never
126
+ }).make({
127
+ init: () => null,
128
+ update: ($) => $.model,
129
+ view: (h) =>
130
+ h.el(Button)
131
+ .props({
132
+ nativeButton: false,
133
+ render: h.render(h.a.props({ href: "/about" }))
134
+ })
135
+ .children("About")
136
+ })
137
+ ```
138
+
139
+ Similarly, if a component prop is needed, the `h.component` utility can be used to pass an Effect UI component back as a React component:
140
+
141
+ ```ts
142
+ import { Schema } from "effect"
143
+ import { React } from "effect-ui-react"
144
+ import { BrowserRouter, Route, Routes } from "react-router"
145
+ import { Counter } from "./Counter"
146
+
147
+ const App = React.component({
148
+ name: "App",
149
+ model: Schema.Null,
150
+ message: Schema.Never
151
+ }).make({
152
+ init: () => null,
153
+ update: ($) => $.model,
154
+ view: (h) =>
155
+ h.el(BrowserRouter).children(
156
+ h.el(Routes).children(
157
+ h.el(Route).props({ path: "/", Component: h.component(Counter) })
158
+ )
159
+ )
160
+ })
161
+ ```
162
+
163
+ Under the hood, this is all still constructed as a React element tree, with Effect UI acting as an external state store.
164
+
165
+ ### Refs
166
+
167
+ Create a typed ref with `Renderer.ref` and attach it with `.ref`. Use `ReactRefs.withRef` inside a command to access the mounted DOM element or imperative handle:
168
+
169
+ ```ts
170
+ import { Input } from "@base-ui/react/input"
171
+ import { Schema } from "effect"
172
+ import { Command, Renderer } from "effect/ui"
173
+ import { React, ReactRefs } from "effect-ui-react"
174
+
175
+ const InputRef = Renderer.ref<HTMLInputElement>("Input")
176
+
177
+ const FocusInput = Command.make("FocusInput", {}, () =>
178
+ ReactRefs.withRef(InputRef, (input) => input.focus())
179
+ )
180
+
181
+ const App = React.component({
182
+ name: "App",
183
+ model: Schema.Null,
184
+ message: Schema.Never
185
+ }).make({
186
+ init: ($) => $.set(null).run(FocusInput.make({}).pipe(Command.asNoop)),
187
+ update: ($) => $.model,
188
+ view: (h) => h.el(Input).ref(InputRef).props({ "aria-label": "Name" })
189
+ })
190
+ ```
191
+
192
+ ### Hooks Compatibility
193
+
194
+ Ideally, state is handled via Effect UI primitives. However, third-party libraries can still expose hooks in their APIs.
195
+
196
+ Wrap the hook in a small React component that passes its value to a render prop. Call the hook inside that React component, not inside the Effect UI view:
197
+
198
+ ```ts
199
+ import { useDirection } from "@base-ui/react"
200
+ import { Schema } from "effect"
201
+ import { React } from "effect-ui-react"
202
+ import type { ReactNode } from "react"
203
+
204
+ function TextDirection(props: { children: (direction: "ltr" | "rtl") => ReactNode }) {
205
+ return props.children(useDirection())
206
+ }
207
+
208
+ const App = React.component({
209
+ name: "App",
210
+ model: Schema.Null,
211
+ message: Schema.Never
212
+ }).make({
213
+ init: () => null,
214
+ update: ($) => $.model,
215
+ view: (h) =>
216
+ h.el(TextDirection).children((direction) =>
217
+ h.p.props({ dir: direction }).children(
218
+ direction === "ltr" ? "Left to right →" : "← Right to left"
219
+ )
220
+ )
221
+ })
222
+ ```
223
+
224
+ ## API
225
+
226
+ ### React.component and view helpers
227
+
228
+ - **`React.component`:** normal Effect UI components with a React vocabulary.
229
+ - **`h.el`:** imported React components with inferred props.
230
+ - **`h.event`:** fixed messages or callbacks mapping arguments to messages; supports default prevention. Return `undefined` to send nothing.
231
+ - **`h.render`:** element props and render callbacks. Function-as-child callbacks are adapted automatically.
232
+ - **`h.component`:** component props with stable wrapper identity and forwarded React props.
233
+
234
+ ### Intrinsic elements
235
+
236
+ - **Shorthands:** `h.div`, `h.input`, `h.svg`, and other tags render intrinsic React elements. `h.el("div")` is the explicit form.
237
+ - **`.props()`:** accepts standard React props, including `className`, `htmlFor`, `style`, and event callbacks adapted with `h.event`.
238
+ - **`.children()`:** supplies text, elements, or Effect UI child components. Void elements such as `input` do not accept children.
239
+ - **`.key()` / `.ref()`:** identify an element and attach a ref.
240
+ - **Custom tags:** import `effect-ui-react/intrinsics` and augment its `IntrinsicElements` interface with your tag names and prop types. Add tags without children to `VoidIntrinsicElements`. The tags must be supported by your React renderer.
241
+
242
+ ### Mounting and embedding
243
+
244
+ - **`mount`:** a scoped Layer; closing its scope unmounts the tree.
245
+ - **`mountEffect`:** a scoped Effect returning the mounted `Renderer.Root`.
246
+ - **`make`:** starts a tree for embedding in React. Returns `Component`, a `root` Promise, and asynchronous `dispose`.
247
+
248
+ The returned `Component` uses Suspense while mounting and error boundaries for mounting failures. Every rendered instance shares one Effect tree. Call `make` outside rendering and call `dispose` when its owner ends; React unmounting alone does not dispose it.
249
+
250
+ `ReactHost` is renderer-agnostic; its mounting functions take a host instance. `ReactDomHost` adds browser services and takes a DOM container. Both accept application props and mount options: `key`, `fallback`, `query`, `head`, and `onEmit`. `make` takes a service Layer instead of a container.
251
+
252
+ ### Refs
253
+
254
+ - **`ReactRefs.lookup`:** resolves a ref to an `Option` of its mounted target after Effect UI and React commit.
255
+ - **`ReactRefs.withRef`:** applies a callback when that target exists, returning an `Option` of its result.
256
+
257
+ Declare refs with `Renderer.ref`. Targets can be DOM elements or imperative handles; missing targets return `Option.none`.
258
+
259
+ ### Browser APIs
260
+
261
+ Import these from `effect-ui-react/dom`:
262
+
263
+ - **`ReactDomCommand`:** focus, scrolling, measurement, and other DOM actions.
264
+ - **`ReactDomSubscription`:** browser events, media queries, visibility, and connectivity.
265
+ - **`ReactDomKeyboard`:** keyboard helpers.
266
+ - **`ReactDomRouter`:** Effect UI browser routing, separate from React Router.
267
+ - **`ReactDomHead`:** document head entries.
268
+ - **`ReactDomFiles` / `ReactDomImages`:** files and image loading.
269
+ - **`ReactDomScheduler`:** browser scheduling.
270
+
271
+ These expose the corresponding Effect UI browser facilities for the React host.
272
+
273
+ ### SSR and hydration
274
+
275
+ - **`ReactDomServer.renderToString`:** renders the first committed tree to HTML and closes its temporary scope. Import from `effect-ui-react/dom/server`.
276
+ - **`ReactDomHost.hydrate`:** a scoped Layer attaching to server-rendered markup.
277
+ - **`ReactDomHost.hydrateEffect`:** the scoped Effect form, returning the root.
278
+
279
+ Match initial component output and props on both sides. Provide services separately; server Models and resources are not transferred to the client.
280
+
281
+ ### Advanced host integration
282
+
283
+ - **`ReactHost.makeHost`:** creates a host with a React `Root`, virtual `container`, and renderer `layer` for manual mounting.
284
+ - **`ReactDomHost.makeHost`:** adds browser services and `renderInto` / `hydrateInto`. Manage both React unmounting and the Effect scope.
285
+ - **`React.Host.afterCommit`:** waits for pending React commits before imperative work.
286
+
287
+ Host options include `onBeforeDispatch`, `onAfterCommit`, `head`, and `controlled`; DOM hosts also accept `document`.
288
+
289
+ ## Package preparation
290
+
291
+ From the repository root:
292
+
293
+ ```sh
294
+ pnpm --filter effect-ui-react check
295
+ pnpm --filter effect-ui-react test
296
+ pnpm pack:react
297
+ ```
298
+
299
+ `pack:react` builds and creates `dist/effect-ui-react-<version>.tgz` locally; it does
300
+ not publish. The archive contains compiled ESM, TypeScript declarations, the
301
+ README and the MIT license. Tests and typecheck fixtures are excluded.
302
+
303
+ Workspace exports target source files for development. Use **pnpm** to pack or
304
+ publish: `publishConfig.exports` switches the archive's exports to compiled
305
+ files, including the separate DOM and server entry points. `prepack` rebuilds
306
+ the package, and `prepublishOnly` runs typechecking and unit tests.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Augmentable registry of intrinsic element tag names -> prop types exposed as
3
+ * fluent shorthands on `h` (e.g. `h.div`, `h.span`) and accepted by `h.el(tag)`.
4
+ *
5
+ * Empty by default in the renderer-agnostic core (`effect-ui-react`). Renderer
6
+ * subpaths (such as `effect-ui-react/dom`) and user apps augment this interface
7
+ * to register their intrinsic elements.
8
+ */
9
+ export interface IntrinsicElements {
10
+ }
11
+ /**
12
+ * Augmentable registry of intrinsic element tag names that do not accept
13
+ * children (such as HTML void elements registered by `effect-ui-react/dom`).
14
+ */
15
+ export interface VoidIntrinsicElements {
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import { Component, View } from "effect/ui";
2
+ import { Context, type Effect, type Option } from "effect";
3
+ import type { IntrinsicElements } from "./Intrinsics.js";
4
+ import { type ComponentHelper, type ElHelper, type EventHelper, type IntrinsicBuilder, type RenderHelper } from "./internal/react-element.js";
5
+ export interface HostService {
6
+ /** Completes once any pending React commit has finished. */
7
+ readonly afterCommit: Effect.Effect<void>;
8
+ /** Unwraps a virtual `HostNode` into its mounted React ref target (DOM node, imperative handle, etc.). */
9
+ readonly resolve: <Node>(node: Node) => Option.Option<Node>;
10
+ /**
11
+ * Awaits any pending or initial React commit for `node`'s owning boundary,
12
+ * then unwraps `node` into its mounted React ref target.
13
+ */
14
+ readonly resolveRef: <Node>(node: Node) => Effect.Effect<Option.Option<Node>>;
15
+ }
16
+ declare const Host_base: Context.ServiceClass<Host, "effect-ui-react/React/Host", HostService>;
17
+ /**
18
+ * The renderer-agnostic React host marker service. Registered in `effect/ui/Command`
19
+ * `FrameworkServices` so commands using it add no requirements to components.
20
+ */
21
+ export declare class Host extends Host_base {
22
+ }
23
+ declare module "effect/ui/Command" {
24
+ interface FrameworkServices {
25
+ readonly ReactHost: Host;
26
+ }
27
+ }
28
+ type ReservedHelperKeys = "props" | "el" | "text" | "isRunning" | "id" | "lazy" | "queries" | "reads" | "slots" | "keepAlive" | "event" | "render" | "component";
29
+ export type IntrinsicElement<K extends keyof IntrinsicElements & string, Msg> = IntrinsicBuilder<K, IntrinsicElements[K], Msg>;
30
+ export type IntrinsicTags<Msg> = {
31
+ readonly [K in Exclude<keyof IntrinsicElements & string, ReservedHelperKeys>]: IntrinsicElement<K, Msg>;
32
+ };
33
+ export type Tags<Msg> = IntrinsicTags<Msg> & {
34
+ readonly el: ElHelper<Msg>;
35
+ readonly event: EventHelper<Msg>;
36
+ readonly render: RenderHelper<Msg>;
37
+ readonly component: ComponentHelper<Host, H<never>>;
38
+ };
39
+ export interface Elements extends View.Elements {
40
+ readonly Tags: Tags<this["Msg"]>;
41
+ readonly Host: Host;
42
+ }
43
+ /**
44
+ * The view helper type for reusable pure React view functions.
45
+ */
46
+ export type H<Msg> = Omit<View.Helper<Msg, unknown>, "el"> & Tags<Msg>;
47
+ export declare const name: "react";
48
+ export declare const vocabulary: View.Vocabulary<Elements>;
49
+ /**
50
+ * Defines a component using the renderer-agnostic React vocabulary
51
+ * (`h.el`, intrinsic JSX tag shorthands like `h.div`, `h.event`, `h.render`,
52
+ * `h.component`), wrapping `h` with the intrinsic tag `Proxy`, each view in a
53
+ * `$boundary` host node for per-component React subscriptions. React-created
54
+ * placements remain children of their originating Effect UI tree, preserving
55
+ * shared owners, collected reports and locally provided services.
56
+ */
57
+ export declare const component: Component.Define<Elements>;
58
+ export {};
package/dist/React.js ADDED
@@ -0,0 +1,55 @@
1
+ import { Component } from "effect/ui";
2
+ import { Context } from "effect";
3
+ import { componentProp, eventHandler, reactEl, renderProp } from "./internal/react-element.js";
4
+ import { wrapHelper } from "./internal/wrap-helper.js";
5
+ import { boundaryView, placementsRead, placementsReadKey } from "./internal/child-placement.js";
6
+ /**
7
+ * The renderer-agnostic React host marker service. Registered in `effect/ui/Command`
8
+ * `FrameworkServices` so commands using it add no requirements to components.
9
+ */
10
+ export class Host extends Context.Service()("effect-ui-react/React/Host") {
11
+ }
12
+ export const name = "react";
13
+ export const vocabulary = {
14
+ name,
15
+ // Static helpers installed on the helper prototype; intrinsic JSX tags are
16
+ // resolved lazily by `wrapHelper` inside `React.component`.
17
+ tags: {
18
+ el: reactEl,
19
+ event: eventHandler,
20
+ render: renderProp,
21
+ component: componentProp
22
+ },
23
+ Elements: undefined
24
+ };
25
+ const defineBase = Component.withElements(vocabulary);
26
+ /**
27
+ * Defines a component using the renderer-agnostic React vocabulary
28
+ * (`h.el`, intrinsic JSX tag shorthands like `h.div`, `h.event`, `h.render`,
29
+ * `h.component`), wrapping `h` with the intrinsic tag `Proxy`, each view in a
30
+ * `$boundary` host node for per-component React subscriptions. React-created
31
+ * placements remain children of their originating Effect UI tree, preserving
32
+ * shared owners, collected reports and locally provided services.
33
+ */
34
+ export const component = ((options) => {
35
+ // Every component reads the placements React descendants registered for it,
36
+ // so it can declare them as its own children without a wrapper component.
37
+ const withPlacements = {
38
+ ...options,
39
+ reads: { ...options.reads, [placementsReadKey]: placementsRead(options.name) }
40
+ };
41
+ const def = defineBase(withPlacements);
42
+ const makeBase = def.make;
43
+ def.make = (rest) => {
44
+ if (typeof rest.view !== "function") {
45
+ const made = makeBase(rest);
46
+ return made;
47
+ }
48
+ const userView = rest.view;
49
+ return makeBase({
50
+ ...rest,
51
+ view: (h, model) => boundaryView(def.name, h, userView(wrapHelper(h), model))
52
+ });
53
+ };
54
+ return def;
55
+ });
@@ -0,0 +1,115 @@
1
+ import { Renderer, type View } from "effect/ui";
2
+ import type { Component } from "effect/ui";
3
+ import type * as AsyncResult from "effect/reactivity/AsyncResult";
4
+ import { Context, Effect, Layer, Scope } from "effect";
5
+ import { type ComponentType, type ReactNode } from "react";
6
+ import * as React from "./React.js";
7
+ import { type BoundaryStore, type ComponentBridgeCache, type HostBridgeContext } from "./internal/react-component-bridge.js";
8
+ import { type EventHandlerCache } from "./internal/to-react-element.js";
9
+ declare const HostNodeBrand: unique symbol;
10
+ interface BoundaryState {
11
+ readonly listeners: Set<() => void>;
12
+ readonly firstCommitWaiters: Set<() => void>;
13
+ readonly store: BoundaryStore;
14
+ committed: boolean;
15
+ dirty: boolean;
16
+ snapshot: ReactNode;
17
+ }
18
+ /**
19
+ * Virtual host node owned by `ReactHost`. React creates the real target nodes
20
+ * (DOM elements, imperative handles, Three.js objects, etc.) when rendering.
21
+ */
22
+ export interface HostNode {
23
+ readonly [HostNodeBrand]: true;
24
+ id: number;
25
+ tag: string;
26
+ text?: string;
27
+ attrs: Record<string, string>;
28
+ props: Record<string, unknown>;
29
+ children: HostNode[];
30
+ parent?: HostNode;
31
+ events?: Renderer.Events;
32
+ /** Mounted target instance captured by React's ref callback, when attached. */
33
+ refTarget?: unknown;
34
+ /** @internal */
35
+ dirty: boolean;
36
+ /** @internal */
37
+ cached?: ReactNode;
38
+ /** @internal */
39
+ handlerCache?: EventHandlerCache;
40
+ /** @internal */
41
+ componentCache?: ComponentBridgeCache;
42
+ /** @internal */
43
+ boundary?: BoundaryState;
44
+ /** @internal */
45
+ refCallback?: (instance: unknown) => void;
46
+ /** @internal */
47
+ renderDispatch?: (msg: unknown) => void;
48
+ /** @internal */
49
+ placementBridge?: HostBridgeContext;
50
+ }
51
+ export interface RootProps {
52
+ readonly children?: ReactNode;
53
+ }
54
+ /**
55
+ * Extensibility hooks for renderer-specific adapters (such as `effect-ui-react/dom`
56
+ * or `effect-ui-nitro`).
57
+ */
58
+ export interface Options {
59
+ /** Called synchronously right before an event handler dispatches into Effect UI. */
60
+ readonly onBeforeDispatch?: ((payload: unknown) => void) | undefined;
61
+ /** Called inside React's post-commit layout effect before resolving `React.Host.afterCommit` waiters. */
62
+ readonly onAfterCommit?: (() => void) | undefined;
63
+ /** Optional head sink invoked whenever Effect UI folds document/host head entries. */
64
+ readonly head?: ((head: unknown) => void) | undefined;
65
+ /** Controlled prop names; defaults to `new Set(["value", "checked", "selected"])`. */
66
+ readonly controlled?: ReadonlySet<string> | undefined;
67
+ }
68
+ export interface Instance {
69
+ readonly host: Renderer.Host<HostNode>;
70
+ readonly reactHost: React.HostService;
71
+ readonly layer: Layer.Layer<Renderer.Renderer | React.Host>;
72
+ readonly container: HostNode;
73
+ readonly Root: ComponentType<RootProps>;
74
+ /** Attaches the live Effect `Context` so bridged `h.component` subtrees inherit app services. */
75
+ readonly setContext: (context: Context.Context<any>) => void;
76
+ }
77
+ export type ReactRoot<V> = [Renderer.HostOf<V>] extends [React.Host] ? unknown : {
78
+ readonly "ReactHost mounts React elements. This root's vocabulary needs": Renderer.HostOf<V>;
79
+ };
80
+ export interface MountOptions<V extends View.Elements, RF = never, Events = unknown> {
81
+ readonly key?: string | undefined;
82
+ readonly fallback?: ((failure: AsyncResult.Failure<never, unknown>, h: View.WithTags<never, {}, V>) => View.Content<never, RF>) | undefined;
83
+ readonly query?: Renderer.QueryOptions | undefined;
84
+ readonly head?: boolean | undefined;
85
+ readonly onEmit?: ((event: Events) => void) | undefined;
86
+ }
87
+ /** Mounts into an existing host for the current Scope, inheriting application services. */
88
+ export declare const mountEffect: <Name extends string, Props, Model, Msg, Events, R, V extends View.Elements, RF = never, RP = never>(component: Component.Members<Name, Props, Model, Msg, Events, R, V, any, never> & ReactRoot<V>, props: Component.PropsInput<Props, never, RP>, renderer: Instance, options?: MountOptions<V, RF, Events> | undefined) => Effect.Effect<Renderer.Root<Model, Msg, Props>, never, Scope.Scope | Exclude<R, React.Host> | Exclude<RF, React.Host> | Exclude<RP, React.Host>>;
89
+ /** A scoped application mount; closing the Layer unmounts the Effect tree. */
90
+ export declare function mount<Name extends string, Props, Model, Msg, Events, R, V extends View.Elements, RF = never, RP = never>(component: Component.Members<Name, Props, Model, Msg, Events, R, V, any> & ReactRoot<V>, props: Component.PropsInput<Props, never, RP>, renderer: Instance, options?: MountOptions<V, RF, Events>): Layer.Layer<never, never, Exclude<R | RF | RP, React.Host>>;
91
+ /** An Effect UI tree mounted outside React, with a component an existing React app renders. */
92
+ export interface Embedded<Model, Msg, Props> {
93
+ /** Renders the tree. Suspends until it has mounted, and throws to the nearest error boundary if mounting fails. */
94
+ readonly Component: ComponentType;
95
+ /** The mounted tree, for driving it from outside React (`send`, `setProps`, `model`). */
96
+ readonly root: Promise<Renderer.Root<Model, Msg, Props>>;
97
+ /** Unmounts the tree and releases everything `layer` built. */
98
+ readonly dispose: () => Promise<void>;
99
+ }
100
+ /**
101
+ * Starts `component` with the services `layer` builds, for an existing React
102
+ * app (or a platform that renders one root component) to render through the
103
+ * returned `Component`. Call it once, at module level: every rendered
104
+ * `Component` shows this one tree, which lives until `dispose` is called.
105
+ */
106
+ export declare function make<Name extends string, Props, Model, Msg, Events, R, V extends View.Elements, E, RF = never, RP = never>(component: Component.Members<Name, Props, Model, Msg, Events, R, V, any> & ReactRoot<V>, props: Component.PropsInput<Props, never, RP>, layer: Layer.Layer<Exclude<R | RF | RP, React.Host>, E>, options?: MountOptions<V, RF, Events> & {
107
+ /** The host to mount into; a fresh `makeHost()` by default. */
108
+ readonly renderer?: Instance | undefined;
109
+ }): Embedded<Model, Msg, Props>;
110
+ /**
111
+ * Creates a renderer-agnostic React host for `effect/ui`.
112
+ * Depends only on `effect`, `effect/ui`, and `react` (no `react-dom` or DOM globals).
113
+ */
114
+ export declare function makeHost(options?: Options): Instance;
115
+ export {};