diff --git a/.changeset/effect-ui-scaffold.md b/.changeset/effect-ui-scaffold.md index cc54d44361..58e3266f13 100644 --- a/.changeset/effect-ui-scaffold.md +++ b/.changeset/effect-ui-scaffold.md @@ -1,15 +1,14 @@ --- "effect": patch -"@effect/ui-html": patch --- -Add `effect/ui`, a Layer-composed frontend framework for Effect, and `@effect/ui-html`, its HTML package. +Add `effect/ui`, a Layer-composed frontend framework for Effect, and `effect/ui/html`, which runs it in the DOM and on the server. The host-agnostic core holds `Component`, `Command`, `Subscription`, `Feature` and `View`, plus `Renderer` to mount a component tree on any host and `MessageLog` to record what it does. `effect/ui/testing` adds `Story` for one-instance tests, `TestHost` and `Query` for runtime tests, and `Story.fromLog` to replay a logged session. `Route` defines a typed route table that parses and prints URLs, `Router` holds the current route with navigation and blocking Commands (`Router.push(AppRoute, route)` takes only routes of the table, `Router.memory` is for tests and `Router.static` for the server), and restores a page's Model on back and forward, skipping the `Command.Service`s declared `server: true`, and a component's `head` option sets the document title, meta, links, JSON-LD and `` / `
` attributes. The modules are experimental. -`@effect/ui-html` runs the same components in a real DOM. `Html` is the element vocabulary (typed events with plain payloads, controlled `value` / `checked` / `selected` / `open`, refs typed by tag, and the `focus`, `blur`, `scrollIntoView` and `measure` ref Commands), `BrowserHost.mount` mounts an HTML root into an element with delegated events and keeps the document head in sync, `BrowserRouter` routes through `window.history` with link interception, scroll restoration and route-change announcements, `HtmlQuery` in `@effect/ui-html/testing` finds elements by ARIA role and accessible name. +`effect/ui/html` runs the same components in a real DOM. It is the only part of `effect/ui` whose types need the `DOM` lib, and nothing else in `effect` re-exports it. `Html` is the element vocabulary (typed events with plain payloads, controlled `value` / `checked` / `selected` / `open`, refs typed by tag, and the `focus`, `blur`, `scrollIntoView` and `measure` ref Commands), `BrowserHost.mount` mounts an HTML root into an element with delegated events and keeps the document head in sync, `BrowserRouter` routes through `window.history` with link interception, scroll restoration and route-change announcements, `HtmlQuery` in `effect/ui/html/testing` finds elements by ARIA role and accessible name. -Server rendering: `HtmlServer.renderToHtml` renders a tree to HTML within a `budget`, running only `init`'s `server: true` Commands, and returns the markup, the state the client adopts, the root's Model and the head as escaped strings. `BrowserHost.mount(App, props, container, { state })` hydrates it, adopting the server's nodes and Models, and `root.adopted` completes when no slot is still waiting for its Layer. `Component.provide(..., { server: false })` keeps a Layer off the server, and `ssr` in `@effect/ui-html/testing` renders, hydrates and checks the two agree. +Server rendering: `HtmlServer.renderToHtml` renders a tree to HTML within a `budget`, running only `init`'s `server: true` Commands, and returns the markup, the state the client adopts, the root's Model and the head as escaped strings. `BrowserHost.mount(App, props, container, { state })` hydrates it, adopting the server's nodes and Models, and `root.adopted` completes when no slot is still waiting for its Layer. `Component.provide(..., { server: false })` keeps a Layer off the server, and `ssr` in `effect/ui/html/testing` renders, hydrates and checks the two agree. ```ts import { Schema } from "effect" diff --git a/.oxlintrc.json b/.oxlintrc.json index 43b87b895a..37d087a880 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -38,5 +38,21 @@ "rules": { "eslint/no-control-regex": "off" } + }, { + // Only effect/ui/html may use DOM types, so nothing else in effect imports it. + "files": ["packages/effect/src/**"], + "rules": { + "eslint/no-restricted-imports": ["error", { + "patterns": [{ + "regex": "(^|/)ui/html(/|$)|^\\.{1,2}/(\\.\\./)*html(/|$)", + "message": "Only effect/ui/html may use DOM types; nothing else in effect may import it." + }] + }] + } + }, { + "files": ["packages/effect/src/ui/html/**"], + "rules": { + "eslint/no-restricted-imports": "off" + } }] } diff --git a/deno.json b/deno.json index 2d317b322c..a4cd36b571 100644 --- a/deno.json +++ b/deno.json @@ -23,7 +23,9 @@ "packages/*/benchmark/", "packages/ai", "packages/atom", + "packages/effect/src/ui/html/", "packages/effect/test/cluster/", + "packages/effect/test/ui/html/", "packages/opentelemetry/", "packages/platform/browser/", "packages/platform/bun/", @@ -31,7 +33,6 @@ "packages/platform/node/", "packages/platform/node-shared/", "packages/tools/", - "packages/ui/", "packages/sql" ] } diff --git a/packages/effect/package.json b/packages/effect/package.json index 26b62c8bf3..df1d9c3f1d 100644 --- a/packages/effect/package.json +++ b/packages/effect/package.json @@ -58,6 +58,8 @@ "./workers": "./src/workers/index.ts", "./ui": "./src/ui/index.ts", "./ui/testing": "./src/ui/testing/index.ts", + "./ui/html": "./src/ui/html/index.ts", + "./ui/html/testing": "./src/ui/html/testing/index.ts", "./*": "./src/*.ts", "./ai/internal/*": null, "./cli/internal/*": null, @@ -74,6 +76,7 @@ "./rpc/internal/*": null, "./workflow/internal/*": null, "./ui/internal/*": null, + "./ui/html/internal/*": null, "./internal/*": null, "./index": null, "./*/index": null @@ -121,6 +124,8 @@ "./workers": "./dist/workers/index.js", "./ui": "./dist/ui/index.js", "./ui/testing": "./dist/ui/testing/index.js", + "./ui/html": "./dist/ui/html/index.js", + "./ui/html/testing": "./dist/ui/html/testing/index.js", "./*": "./dist/*.js", "./internal/*": null, "./cli/internal/*": null, @@ -138,6 +143,7 @@ "./rpc/internal/*": null, "./workflow/internal/*": null, "./ui/internal/*": null, + "./ui/html/internal/*": null, "./index": null, "./*/index": null } diff --git a/packages/effect/src/ui/Router.ts b/packages/effect/src/ui/Router.ts index f30a78a3fa..1b9640d159 100644 --- a/packages/effect/src/ui/Router.ts +++ b/packages/effect/src/ui/Router.ts @@ -4,7 +4,7 @@ * * `Router` is a host service. Its Layers are `Router.memory` (tests and * `TestHost`), `Router.static` (server rendering) and, in - * `@effect/ui-html`, `BrowserRouter.layer` and `BrowserRouter.layerHash`. + * `effect/ui/html`, `BrowserRouter.layer` and `BrowserRouter.layerHash`. * Each provides the `Router` service and the navigation Commands, `Push`, * `Replace`, `Back`, `Forward`, `Load`, `Block` and `Unblock`. A component * that navigates has them in its requirements, so a missing Router is a diff --git a/packages/ui/html/src/BrowserHost.ts b/packages/effect/src/ui/html/BrowserHost.ts similarity index 97% rename from packages/ui/html/src/BrowserHost.ts rename to packages/effect/src/ui/html/BrowserHost.ts index 213269641a..175b1fdb56 100644 --- a/packages/ui/html/src/BrowserHost.ts +++ b/packages/effect/src/ui/html/BrowserHost.ts @@ -17,7 +17,7 @@ * **Example** (Mounting an app) * * ```ts - * import { BrowserHost, Html } from "@effect/ui-html" + * import { BrowserHost, Html } from "effect/ui/html" * import { Effect, Schema } from "effect" * import { Component } from "effect/ui" * @@ -42,14 +42,14 @@ * @stability experimental * @since 4.1.3 */ -import * as Context from "effect/Context" -import * as Effect from "effect/Effect" -import * as Layer from "effect/Layer" -import type * as AsyncResult from "effect/reactivity/AsyncResult" -import type * as Scope from "effect/Scope" -import type * as Component from "effect/ui/Component" -import * as Renderer from "effect/ui/Renderer" -import type * as View from "effect/ui/View" +import * as Context from "../../Context.ts" +import * as Effect from "../../Effect.ts" +import * as Layer from "../../Layer.ts" +import type * as AsyncResult from "../../reactivity/AsyncResult.ts" +import type * as Scope from "../../Scope.ts" +import type * as Component from "../Component.ts" +import * as Renderer from "../Renderer.ts" +import type * as View from "../View.ts" import * as Html from "./Html.ts" import * as headSync from "./internal/head.ts" import * as markers from "./internal/markers.ts" diff --git a/packages/ui/html/src/BrowserRouter.ts b/packages/effect/src/ui/html/BrowserRouter.ts similarity index 97% rename from packages/ui/html/src/BrowserRouter.ts rename to packages/effect/src/ui/html/BrowserRouter.ts index 330fd8ca74..3a0768bbbb 100644 --- a/packages/ui/html/src/BrowserRouter.ts +++ b/packages/effect/src/ui/html/BrowserRouter.ts @@ -22,7 +22,7 @@ * **Example** (A two-page app) * * ```ts - * import { BrowserHost, BrowserRouter, Html } from "@effect/ui-html" + * import { BrowserHost, BrowserRouter, Html } from "effect/ui/html" * import { Effect, Layer, Option, Schema } from "effect" * import { Component, Route, Router } from "effect/ui" * @@ -64,12 +64,12 @@ * @stability experimental * @since 4.1.3 */ -import * as Context from "effect/Context" -import * as Effect from "effect/Effect" -import * as Layer from "effect/Layer" -import * as Option from "effect/Option" -import type * as Route from "effect/ui/Route" -import * as Router from "effect/ui/Router" +import * as Context from "../../Context.ts" +import * as Effect from "../../Effect.ts" +import * as Layer from "../../Layer.ts" +import * as Option from "../../Option.ts" +import type * as Route from "../Route.ts" +import * as Router from "../Router.ts" import * as submit from "./internal/submit.ts" /** diff --git a/packages/ui/html/src/Html.ts b/packages/effect/src/ui/html/Html.ts similarity index 97% rename from packages/ui/html/src/Html.ts rename to packages/effect/src/ui/html/Html.ts index b800e3bf4d..1b48ca673c 100644 --- a/packages/ui/html/src/Html.ts +++ b/packages/effect/src/ui/html/Html.ts @@ -16,7 +16,7 @@ * **Example** (Registering the vocabulary for the app) * * ```ts - * import { Html } from "@effect/ui-html" + * import { Html } from "effect/ui/html" * import { View } from "effect/ui" * * declare module "effect/ui/View" { @@ -31,7 +31,7 @@ * **Example** (A controlled text field) * * ```ts import.meta.vitest - * import { Html } from "@effect/ui-html" + * import { Html } from "effect/ui/html" * import { Schema } from "effect" * import { Component } from "effect/ui" * @@ -58,12 +58,12 @@ * @stability experimental * @since 4.1.3 */ -import * as Context from "effect/Context" -import * as Effect from "effect/Effect" -import * as Option from "effect/Option" -import * as Command from "effect/ui/Command" -import * as Renderer from "effect/ui/Renderer" -import * as View from "effect/ui/View" +import * as Context from "../../Context.ts" +import * as Effect from "../../Effect.ts" +import * as Option from "../../Option.ts" +import * as Command from "../Command.ts" +import * as Renderer from "../Renderer.ts" +import * as View from "../View.ts" // --------------------------------------------------------------------------- // host @@ -89,9 +89,9 @@ export class Host extends Context.Service