@valbuild/tanstack 0.154.1 → 0.154.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # @valbuild/tanstack
2
2
 
3
+ ## 0.154.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1087](https://github.com/valbuild/val/pull/1087) [`9e085bc`](https://github.com/valbuild/val/commit/9e085bc2b2104ce2644b4a14948288c799a2ce82) Thanks [@freekh](https://github.com/freekh)! - **A published page no longer loads the Studio, TypeScript, sucrase or prettier.** A site's first request in a fresh server process (on Val's hosting, every request a cold isolate answers) used to evaluate all of Val's server: the Studio's embedded assets (about 22 MB), TypeScript (9 MB), sucrase and the MCP tools. A page only needs that when someone edits it. These now load when they are first used, by the Val API, a draft read, a save or an MCP call, and a visitor's page never loads them.
8
+
9
+ We measured this in a fresh Node process, with the TanStack example app built the way a deployed app is built and running as a deployed site does (`http` mode). The first request for a public page used to load 38.8 MB of modules, take about 1.06 s and leave 170 MB of heap in use. It now loads 5.3 MB, takes about 0.23 s and leaves 38 MB of heap. An isolate counts more than Node does, so treat these heap figures as a lower bound.
10
+
11
+ What changed for an app:
12
+
13
+ - `initValContent` (and `initValRsc` in `@valbuild/next`) no longer start Val's server when they are created. They start it on the first draft read.
14
+ - With TanStack Start, `initValServer` loads the server on its first request in `http` mode, which is what a deployed site runs in. In local development (`fs` mode) and memory mode it still starts with the app. Those modes need the newest build in a process to exist before the previous build answers a request.
15
+ - `initValMcp` from `@valbuild/tanstack/server` loads the MCP tools on the first MCP request. Its `valMcpMetadata` comes from the new `@valbuild/mcp/metadata` entry, which is small.
16
+ - `createPrettierFormatter` now also accepts a loader. **Update your `val.server.ts`** so prettier is loaded by the first save rather than by every page:
17
+
18
+ ```ts
19
+ // before
20
+ import prettier from "prettier";
21
+ formatter: createPrettierFormatter(prettier, { projectRoot: process.cwd() }),
22
+
23
+ // after
24
+ formatter: createPrettierFormatter(() => import("prettier"), {
25
+ projectRoot: process.cwd(),
26
+ }),
27
+ ```
28
+
29
+ Passing `prettier` itself still works.
30
+
31
+ - If your app serves MCP from a TanStack Start route, import the MCP SDK inside the handler (`await import("@modelcontextprotocol/server")`), not at the top of the file. TanStack Start's route tree imports every server route's module on every cold start.
32
+
33
+ - [#1049](https://github.com/valbuild/val/pull/1049) [`d90b9e2`](https://github.com/valbuild/val/commit/d90b9e2f856d4023821698cd22b4fbbab046c2ff) Thanks [@freekh](https://github.com/freekh)! - Experimental: link an object to the component that renders it, and let Val render and arrange it
34
+
35
+ `s.object(...).component(() => import("./Hero"))` links an object schema to a component. The link is type checked against the component's own props: when the object's fields are the props nothing else is needed, and for any other component a `props` function says how to make them.
36
+
37
+ ```ts
38
+ export const heroFields = s.object({
39
+ type: s.literal("hero"),
40
+ title: s.string(),
41
+ });
42
+ export const hero = heroFields.component(() => import("../components/Hero"));
43
+
44
+ export const note = s
45
+ .object({ type: s.literal("note"), title: s.string(), urgent: s.boolean() })
46
+ .component(() => import("../components/Callout"), {
47
+ props: (note) => ({
48
+ heading: note.title,
49
+ tone: note.urgent ? "warning" : "info",
50
+ }),
51
+ });
52
+ ```
53
+
54
+ `<ValComponentEditor value={page.sections} />`, from `@valbuild/tanstack` and `@valbuild/next`, renders a list of linked objects (or a single one) with their components, with no map from a `type` to a component to keep. It only accepts values that are linked: a list with a variant that has no component is a type error. It is optional, and a component can use it for a list of components of its own.
55
+
56
+ In Val Studio, a list rendered this way can be arranged on the page itself: drag a section to another place, add one between two others, or remove one.
57
+
58
+ This replaces the experimental `.render({ as: "component", component })` on objects. Move its `component` to the first argument of `.component()` and the rest of its options to the second.
59
+
60
+ - Updated dependencies [[`9e085bc`](https://github.com/valbuild/val/commit/9e085bc2b2104ce2644b4a14948288c799a2ce82), [`d90b9e2`](https://github.com/valbuild/val/commit/d90b9e2f856d4023821698cd22b4fbbab046c2ff), [`180b6b7`](https://github.com/valbuild/val/commit/180b6b7513226009e7eb6a768282d70685ccf436), [`a52c184`](https://github.com/valbuild/val/commit/a52c184687849ba9c2c2a4929871b60502a6ee55), [`6c26409`](https://github.com/valbuild/val/commit/6c2640966779e20931672dc78ff6e3c0d19e4183), [`d90b9e2`](https://github.com/valbuild/val/commit/d90b9e2f856d4023821698cd22b4fbbab046c2ff)]:
61
+ - @valbuild/server@0.154.2
62
+ - @valbuild/mcp@0.154.2
63
+ - @valbuild/core@0.154.2
64
+ - @valbuild/react@0.154.2
65
+ - @valbuild/shared@0.154.2
66
+ - @valbuild/ui@0.154.2
67
+ - @valbuild/language-server@0.154.2
68
+
3
69
  ## 0.154.1
4
70
 
5
71
  ### Patch Changes
package/README.md CHANGED
@@ -51,6 +51,7 @@ this package mounts at `/val`.
51
51
  - [Reading content](#reading-content)
52
52
  - [Routes](#routes)
53
53
  - [Preview and draft mode](#preview-and-draft-mode)
54
+ - [Components (experimental)](#components-experimental)
54
55
  - [Images](#images)
55
56
  - [Coding agents (MCP)](#coding-agents-mcp)
56
57
  - [Differences from `@valbuild/next`](#differences-from-valbuildnext)
@@ -398,6 +399,119 @@ nothing for it. It needs React 19 and a `<Suspense>` boundary (see above). With
398
399
  `draft` given, the server already has that page's content, so its first render
399
400
  does not 404 either.
400
401
 
402
+ ## Components (experimental)
403
+
404
+ An object schema can be linked to the component that renders it:
405
+
406
+ ```ts
407
+ // src/routes/landing.val.ts
408
+ export const heroFields = s.object({
409
+ type: s.literal("hero"),
410
+ title: s.string(),
411
+ });
412
+ export const hero = heroFields.component(
413
+ () => import("../components/HeroSection"),
414
+ {
415
+ example: { type: "hero", title: "A very long title, to test the layout" },
416
+ },
417
+ );
418
+ ```
419
+
420
+ The import is lazy: Val evaluates `.val.ts` files outside your app, where a
421
+ component's CSS and framework code cannot be loaded, and never calls it there.
422
+ On the site it means a page downloads the components it shows and no others.
423
+
424
+ It is type checked against the component's own props. When the object's
425
+ fields are the props, nothing else is needed. For a component that was not
426
+ written for the schema - one from a design system, say - add a `props`
427
+ function, which is then required and whose result is checked instead:
428
+
429
+ ```ts
430
+ export const note = s
431
+ .object({ type: s.literal("note"), title: s.string(), urgent: s.boolean() })
432
+ .component(() => import("../components/Callout"), {
433
+ props: (note) => ({
434
+ heading: note.title,
435
+ tone: note.urgent ? "warning" : "info",
436
+ }),
437
+ });
438
+ ```
439
+
440
+ `props` is given the value as `useVal` returns it, so a string it passes on
441
+ unchanged can still be clicked to edit, and one it transforms cannot.
442
+
443
+ A component that types its props from its schema must read them from the
444
+ FIELDS (`t.inferSchema<typeof heroFields>`), not from the linked schema: that
445
+ one's type depends on the component's, and TypeScript will not resolve the
446
+ circle.
447
+
448
+ ### Rendering: `ValComponentEditor`
449
+
450
+ ```tsx
451
+ import { ValComponentEditor } from "@valbuild/tanstack";
452
+
453
+ function Landing() {
454
+ const page = useValRoute(pageVal, {});
455
+ return <ValComponentEditor value={page.sections} />;
456
+ }
457
+ ```
458
+
459
+ Each object is rendered by the component its own schema links it to, so there
460
+ is no `type` to component map to keep. It takes a list or a single object,
461
+ and only ones that are linked: a list with a variant that has no component,
462
+ or an object that never had one, is a type error.
463
+
464
+ It is optional. The same content can be rendered by hand with a `map` and a
465
+ `switch`, and a page can use it for one list and not for the rest of what it
466
+ shows. A component can use it too, for a list of components of its own.
467
+
468
+ In Val Studio, on the page itself, a list rendered this way can be arranged:
469
+ drag a section to another place, add one between two others, remove one.
470
+
471
+ Render the value where it was read. The component rides on the value, and a
472
+ value passed through a serializing boundary (loader data, a server function's
473
+ result) arrives without it.
474
+
475
+ ### A preview route
476
+
477
+ A linked object can also be rendered on its own, by your app, at
478
+ `/val-preview?p=<source path>` - with `&example=1`, from its `example`. Val
479
+ Studio does not load it yet: it is there for a component view that is still
480
+ to come. To have it, add the route outside the layout that holds
481
+ `ValProvider`:
482
+
483
+ ```tsx
484
+ // src/val/server.ts
485
+ export const fetchValPreviewSource = (sourcePath: string) =>
486
+ unstable_fetchValPreviewSource({ valModules, fetchVal, sourcePath });
487
+
488
+ // src/routes/val-preview.tsx
489
+ const getPreviewSource = createServerFn()
490
+ .validator((sourcePath: string) => sourcePath)
491
+ .handler(({ data }) => fetchValPreviewSource(data));
492
+
493
+ export const Route = createFileRoute("/val-preview")({
494
+ ssr: false,
495
+ validateSearch: (search: Record<string, unknown>) => ({
496
+ p: String(search.p ?? ""),
497
+ example: search.example === undefined ? undefined : String(search.example),
498
+ }),
499
+ loaderDeps: ({ search }) => ({ p: search.p }),
500
+ loader: ({ deps }) => getPreviewSource({ data: deps.p }),
501
+ component: () => (
502
+ <ValPreviewBridge>
503
+ <Unstable_ValComponentPreview
504
+ valModules={valModules}
505
+ source={Route.useLoaderData()}
506
+ example={Route.useSearch().example === "1"}
507
+ />
508
+ </ValPreviewBridge>
509
+ ),
510
+ });
511
+ ```
512
+
513
+ `examples/tanstack/src/routes/val-preview.tsx` is a working copy.
514
+
401
515
  ## Content analytics
402
516
 
403
517
  Val can count which content your visitors see. On a site Val hosts it is
@@ -0,0 +1,28 @@
1
+ import type { ValModules } from "@valbuild/core";
2
+ import type { ValPreviewSource } from "./server/fetchValPreviewSource.js";
3
+ /**
4
+ * EXPERIMENTAL: renders the value at a source path with the component its
5
+ * schema declares - `s.object(...).component(() => import(...))`.
6
+ *
7
+ * The TanStack half of a component preview. The content is read on the server
8
+ * (`unstable_fetchValPreviewSource` from `@valbuild/tanstack/server`, through
9
+ * a server function in the route's loader), and the component is found and
10
+ * rendered here, in the browser: its `import()` is the app's own, so it is
11
+ * the app's code that renders it, with the app's CSS.
12
+ *
13
+ * `source` is what the loader returned; the rest says what to render.
14
+ *
15
+ * `Unstable_` rather than `unstable_` like `@valbuild/next`'s
16
+ * `unstable_renderValComponent`: this one is a component, and JSX reads a tag
17
+ * that starts with a lower-case letter as an HTML element.
18
+ */
19
+ export declare function Unstable_ValComponentPreview({ valModules, source, example, props, }: {
20
+ /** The app's `val.modules` registry (the default export of val.modules.ts). */
21
+ valModules: ValModules;
22
+ /** What `unstable_fetchValPreviewSource` returned for the source path. */
23
+ source: ValPreviewSource;
24
+ /** Render the render's `example` instead of the content. */
25
+ example?: boolean;
26
+ /** Props to render with instead, written as source. */
27
+ props?: unknown;
28
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,27 @@
1
+ import type { ReactNode } from "react";
2
+ /**
3
+ * EXPERIMENTAL: the preview route's side of its conversation with the Studio.
4
+ * Wrap `Unstable_ValComponentPreview` in it.
5
+ *
6
+ * It keeps the frame as tall as the component, sends a click on content to
7
+ * the Studio so it can open that field, and reads the content again when an
8
+ * edit is made - `router.invalidate()`, which re-runs the route's loader. See
9
+ * `ValPreviewBridgeCore` in `@valbuild/react/internal` for the details.
10
+ *
11
+ * It also switches on the edit tags. Everywhere else `ValProvider` does that,
12
+ * once hydration has told it the Studio is open; the preview route is not
13
+ * under the site's `ValProvider`, and is rendered in the browser only
14
+ * (`ssr: false`), so it can tag from its first render.
15
+ *
16
+ * @example
17
+ * // src/routes/val-preview.tsx
18
+ * <ValPreviewBridge>
19
+ * <Unstable_ValComponentPreview
20
+ * valModules={valModules}
21
+ * source={Route.useLoaderData()}
22
+ * />
23
+ * </ValPreviewBridge>
24
+ */
25
+ export declare function ValPreviewBridge({ children }: {
26
+ children: ReactNode;
27
+ }): import("react").JSX.Element;
@@ -15,6 +15,10 @@ export { type SelectorSource, type SelectorOf, GenericSelector, } from "@valbuil
15
15
  export { ValRichText } from "@valbuild/react/internal";
16
16
  export { type ValEncodedString, type File, type Image, type Video, type RichText, } from "@valbuild/react/stega";
17
17
  export { ValProvider } from "./ValProvider.js";
18
+ export { ValPreviewBridge } from "./ValPreviewBridge.js";
19
+ export { ValComponentEditor, type ValComponentEditorProps, } from "@valbuild/react/internal";
20
+ export { Unstable_ValComponentPreview } from "./ValComponentPreview.js";
21
+ export type { ValPreviewSource } from "./server/fetchValPreviewSource.js";
18
22
  export type { ValDraft } from "./ValDraft.js";
19
23
  export type { ValAnalytics } from "./ValAnalytics.js";
20
24
  export { ValImage, type ValImageProps } from "./ValImage.js";
@@ -0,0 +1,34 @@
1
+ import type { SelectorSource, ValModule, ValModules } from "@valbuild/core";
2
+ /** What `unstable_fetchValPreviewSource` returns; serializable, for a loader. */
3
+ export type ValPreviewSource =
4
+ /**
5
+ * The content as JSON text: a server function's result has to be
6
+ * serializable, and a module's content is typed per module by the app, so
7
+ * text is what can be promised. The edit tags are characters in the
8
+ * strings, and survive it.
9
+ */
10
+ {
11
+ status: "ok";
12
+ sourcePath: string;
13
+ moduleJson: string;
14
+ } | {
15
+ status: "error";
16
+ message: string;
17
+ };
18
+ /**
19
+ * EXPERIMENTAL: the content of the module `sourcePath` is in, as the app reads
20
+ * it - for `Unstable_ValComponentPreview`, which renders the value at the path
21
+ * with its component.
22
+ *
23
+ * Call it from a server function: it reads with the app's own `fetchVal`, so
24
+ * an editor in draft mode gets the draft, with edit tags.
25
+ *
26
+ * The whole module rather than the value at the path, because which schema the
27
+ * path ends in can depend on the content along the way (a union's variant), and
28
+ * the browser has to walk it to find the component.
29
+ */
30
+ export declare function unstable_fetchValPreviewSource({ valModules, fetchVal, sourcePath, }: {
31
+ valModules: ValModules;
32
+ fetchVal: (module: ValModule<SelectorSource>) => Promise<unknown>;
33
+ sourcePath: string;
34
+ }): Promise<ValPreviewSource>;
@@ -1,10 +1,11 @@
1
1
  export { initValServer } from "./initValServer.js";
2
- export { InMemoryPatchStore, type ValPatchStore } from "@valbuild/server";
2
+ export { InMemoryPatchStore, type ValPatchStore, } from "@valbuild/server/internal";
3
3
  export type { ValHttpMode } from "./initValServer.js";
4
4
  export { initValContent } from "./initValContent.js";
5
5
  export type { ValDraft } from "../ValDraft.js";
6
6
  export type { ValAnalytics } from "../ValAnalytics.js";
7
7
  export { valDraftMode, hasValEnableCookieOnServer, VAL_DRAFT_MODE_COOKIE, type ValDraftMode, } from "./valDraftMode.js";
8
8
  export { initValMcp } from "./initValMcp.js";
9
- export { createPrettierFormatter, type PrettierLike, type ValFormatter, } from "@valbuild/server";
9
+ export { createPrettierFormatter, type PrettierLike, type PrettierLoader, type ValFormatter, } from "@valbuild/server/internal";
10
10
  export type { ValMcp, ValMcpAuthorizationResult, ValMcpMetadataHandlers, ValOAuthConfig, ValToolImpl, } from "@valbuild/mcp";
11
+ export { unstable_fetchValPreviewSource, type ValPreviewSource, } from "./fetchValPreviewSource.js";
@@ -1,17 +1,17 @@
1
1
  import { type JsonEntryContentOf, type Resolvable, type ResolvedVal, type RouteValueOf } from "@valbuild/react/stega";
2
2
  import { type Ready } from "@valbuild/react/internal";
3
3
  import { ModuleFilePath, ValConfig, ValModules, type Json, type ResolvableModule } from "@valbuild/core";
4
- import { type ValPatchStore } from "@valbuild/server";
5
- import { type ValRuntime } from "@valbuild/server/internal";
4
+ import { type ReaderRuntime, type ValPatchStore } from "@valbuild/server/internal";
6
5
  import { type ValDraftMode } from "./valDraftMode.js";
7
6
  import type { ValDraft } from "../ValDraft.js";
8
7
  import type { ValHttpMode } from "./initValServer.js";
9
8
  /**
10
9
  * What the readers read: this process's runtime for the app's `val.modules`
11
10
  * (`createValRuntime`), the same one `initValServer`'s server is built on.
12
- * Its head is the draft, read with the request's session.
11
+ * Its head is the draft, read with the request's session. Asked for by the
12
+ * first draft read, never by a visitor's.
13
13
  */
14
- export type ReaderRuntime = Promise<ValRuntime>;
14
+ export type { ReaderRuntime };
15
15
  /** What a reader needs from the app and the request. */
16
16
  export type ReaderDeps = {
17
17
  runtime: ReaderRuntime;
@@ -25,8 +25,11 @@ export type ReaderDeps = {
25
25
  value: string;
26
26
  } | undefined;
27
27
  }>;
28
- /** A proposal's saved Source; see `ValDraft.snapshot`. */
29
- snapshot?: Snapshot;
28
+ /**
29
+ * A proposal's saved Source; see `ValDraft.snapshot`. Possibly still being
30
+ * read: see {@link snapshotForReaders}.
31
+ */
32
+ snapshot?: Snapshot | Promise<Snapshot | undefined>;
30
33
  };
31
34
  export declare const initFetchValStega: (deps: ReaderDeps) => <T extends Resolvable>(selector: T) => Promise<ResolvedVal<T>>;
32
35
  /** A proposal's saved Source, by module: see `ValProposal` in `@valbuild/server`. */
@@ -35,8 +38,12 @@ type Snapshot = Record<ModuleFilePath, Json>;
35
38
  * What the readers render over the bundle: a proposal's saves over the
36
39
  * content version the site serves (`layeredSnapshot` in @valbuild/server),
37
40
  * either alone, or nothing.
41
+ *
42
+ * A promise because a saved `.jsonValues()` entry takes the compiler to place
43
+ * (`readerSnapshot`), which is loaded only then: a snapshot without one is
44
+ * ready at once, and no snapshot at all is `undefined`.
38
45
  */
39
- export declare function snapshotForReaders(http: Pick<ValHttpMode, "proposal" | "contentVersion" | "projectSource" | "moduleDependencies"> | undefined): Snapshot | undefined;
46
+ export declare function snapshotForReaders(http: Pick<ValHttpMode, "proposal" | "contentVersion" | "projectSource" | "moduleDependencies"> | undefined): Promise<Snapshot | undefined>;
40
47
  /**
41
48
  * Where an isolate says which content version it applied, for the platform
42
49
  * serving it to read back after a render (valbuild/home: the loader answers it
@@ -186,4 +193,3 @@ export declare function initValContent(config: ValConfig, valModules: ValModules
186
193
  */
187
194
  fetchValDraft: ReturnType<typeof initFetchValDraft>;
188
195
  };
189
- export {};
@@ -1,5 +1,5 @@
1
1
  import type { ValConfig, ValModules } from "@valbuild/core";
2
- import { type ValMcp, type ValToolImpl, type ValOAuthConfig } from "@valbuild/mcp";
2
+ import type { ValMcp, ValToolImpl, ValOAuthConfig } from "@valbuild/mcp";
3
3
  /**
4
4
  * Val's tools over MCP, bound to this package.
5
5
  *
@@ -11,6 +11,13 @@ import { type ValMcp, type ValToolImpl, type ValOAuthConfig } from "@valbuild/mc
11
11
  *
12
12
  * The version goes in the `next` field because that is the field name in the
13
13
  * wire contract; see `initValServer`.
14
+ *
15
+ * `@valbuild/mcp` is loaded by the first MCP request, not by this module: it
16
+ * brings Val's whole server (the tools run against its data layer), and an
17
+ * app's MCP route is imported by TanStack Start's route tree on every cold
18
+ * start, so a static import made every visitor's first request pay for it. The
19
+ * metadata document is the one part that must exist up front, and comes from
20
+ * `@valbuild/mcp/metadata`, which is light.
14
21
  */
15
22
  export declare function initValMcp(valModules: ValModules, config: ValConfig, opts?: {
16
23
  formatter?: (code: string, filePath: string) => string | Promise<string>;
@@ -1,5 +1,5 @@
1
1
  import { ValConfig, ValModules } from "@valbuild/core";
2
- import { type CommitContext, type CommitResult, type ValPatchStore, type ValContentVersion, type ValProposal } from "@valbuild/server";
2
+ import type { CommitContext, CommitResult, ValPatchStore, ValContentVersion, ValProposal } from "@valbuild/server";
3
3
  import { type ValDraftMode } from "./valDraftMode.js";
4
4
  /**
5
5
  * What `http` mode needs, as one object.
@@ -6,7 +6,7 @@ var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
6
6
  var _typeof = require('./typeof-bd6ec82c.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
9
- var version = require('./version-43593a0a.cjs.dev.js');
9
+ var version = require('./version-1387cb76.cjs.dev.js');
10
10
  var internal = require('@valbuild/react/internal');
11
11
  var ui = require('@valbuild/ui');
12
12
  var reactRouter = require('@tanstack/react-router');
@@ -313,6 +313,15 @@ function ValCanvasBridge(_ref) {
313
313
  // installed once and would otherwise close over the first value forever.
314
314
  var pickingRef = React__default["default"].useRef(false);
315
315
  pickingRef.current = picking;
316
+ // Said on the document too, for the controls `ValComponentEditor` draws:
317
+ // they are shown only while Select is on.
318
+ React__default["default"].useEffect(function () {
319
+ var root = document.documentElement;
320
+ root.toggleAttribute(client.VAL_CANVAS_EDITING_ATTRIBUTE, picking);
321
+ return function () {
322
+ return root.removeAttribute(client.VAL_CANVAS_EDITING_ATTRIBUTE);
323
+ };
324
+ }, [picking]);
316
325
  /**
317
326
  * Picking ANY element (`pickElements`), as the studio last said. `null`
318
327
  * until it says.
@@ -973,6 +982,9 @@ function ValCanvasBridge(_ref) {
973
982
  var _heldKeys$current2;
974
983
  var target = event.target;
975
984
  if (!(target instanceof Element)) return;
985
+ // Val's own controls on a list of components, not the page's content:
986
+ // the click is theirs, wherever in the page they are drawn.
987
+ if (client.isOnValCanvasControls(target)) return;
976
988
  // A click in the field being typed in places the caret, and that is
977
989
  // all it does: it is neither a pick nor a click on the link or button
978
990
  // the text happens to be in. (The caret is the mousedown's, so
@@ -1279,7 +1291,14 @@ function ValCanvasBridge(_ref) {
1279
1291
  // CSS string. A path contains quotes (`?p="/"`) and would otherwise
1280
1292
  // close the selector early.
1281
1293
  dangerouslySetInnerHTML: {
1282
- __html: [picking ? "[data-val-path] { outline: 1px solid ".concat(selectionColors.selectionSoft, "; outline-offset: 1px; cursor: pointer; }\n[data-val-path]:hover { outline: 2px solid ").concat(selectionColors.selection, "; }") : "",
1294
+ __html: [":root { ".concat(client.VAL_CANVAS_SELECTION_PROPERTY, ": ").concat(selectionColors.selection, "; }"),
1295
+ // Not around a component's item: its controls outline it, and two
1296
+ // boxes on one element is one too many. The conditions are in
1297
+ // `:where()`, which counts for nothing: this rule must stay as
1298
+ // weak as `[data-val-path]` alone, or it beats the outline of the
1299
+ // field the Studio is on (`highlightRule`, below) and that field
1300
+ // looks like every other one while Select is on.
1301
+ picking ? ":where(:root:not([".concat(client.VAL_COMPONENT_DRAGGING_ATTRIBUTE, "])) [data-val-path]:where(:not([").concat(client.VAL_COMPONENT_ATTRIBUTE, "])) { outline: 1px solid ").concat(selectionColors.selectionSoft, "; outline-offset: 1px; cursor: pointer; }\n:where(:root:not([").concat(client.VAL_COMPONENT_DRAGGING_ATTRIBUTE, "])) [data-val-path]:where(:not([").concat(client.VAL_COMPONENT_ATTRIBUTE, "])):hover { outline: 2px solid ").concat(selectionColors.selection, "; }") : "",
1283
1302
  // The one rule here that moves the page, and only while Select is
1284
1303
  // on: an emptied text's line of room, without which it cannot be
1285
1304
  // pointed at. See `emptyTextFields.ts` for why, and how narrowly.
@@ -2726,6 +2745,143 @@ function readParentPathname() {
2726
2745
 
2727
2746
  var ValProvider = ValTanStackProvider;
2728
2747
 
2748
+ /**
2749
+ * EXPERIMENTAL: the preview route's side of its conversation with the Studio.
2750
+ * Wrap `Unstable_ValComponentPreview` in it.
2751
+ *
2752
+ * It keeps the frame as tall as the component, sends a click on content to
2753
+ * the Studio so it can open that field, and reads the content again when an
2754
+ * edit is made - `router.invalidate()`, which re-runs the route's loader. See
2755
+ * `ValPreviewBridgeCore` in `@valbuild/react/internal` for the details.
2756
+ *
2757
+ * It also switches on the edit tags. Everywhere else `ValProvider` does that,
2758
+ * once hydration has told it the Studio is open; the preview route is not
2759
+ * under the site's `ValProvider`, and is rendered in the browser only
2760
+ * (`ssr: false`), so it can tag from its first render.
2761
+ *
2762
+ * @example
2763
+ * // src/routes/val-preview.tsx
2764
+ * <ValPreviewBridge>
2765
+ * <Unstable_ValComponentPreview
2766
+ * valModules={valModules}
2767
+ * source={Route.useLoaderData()}
2768
+ * />
2769
+ * </ValPreviewBridge>
2770
+ */
2771
+ function ValPreviewBridge(_ref) {
2772
+ var children = _ref.children;
2773
+ var router = reactRouter.useRouter();
2774
+ // Before the children render, so their JSX is created with the tags on.
2775
+ // A global switch, and idempotent: setting it again on a re-render is free.
2776
+ stega.SET_AUTO_TAG_JSX_ENABLED(true);
2777
+ return /*#__PURE__*/jsxRuntime.jsx(internal.ValPreviewBridgeCore, {
2778
+ onRefresh: function onRefresh() {
2779
+ return router.invalidate();
2780
+ },
2781
+ children: children
2782
+ });
2783
+ }
2784
+
2785
+ /**
2786
+ * EXPERIMENTAL: renders the value at a source path with the component its
2787
+ * schema declares - `s.object(...).component(() => import(...))`.
2788
+ *
2789
+ * The TanStack half of a component preview. The content is read on the server
2790
+ * (`unstable_fetchValPreviewSource` from `@valbuild/tanstack/server`, through
2791
+ * a server function in the route's loader), and the component is found and
2792
+ * rendered here, in the browser: its `import()` is the app's own, so it is
2793
+ * the app's code that renders it, with the app's CSS.
2794
+ *
2795
+ * `source` is what the loader returned; the rest says what to render.
2796
+ *
2797
+ * `Unstable_` rather than `unstable_` like `@valbuild/next`'s
2798
+ * `unstable_renderValComponent`: this one is a component, and JSX reads a tag
2799
+ * that starts with a lower-case letter as an HTML element.
2800
+ */
2801
+ function Unstable_ValComponentPreview(_ref) {
2802
+ var valModules = _ref.valModules,
2803
+ source = _ref.source,
2804
+ example = _ref.example,
2805
+ props = _ref.props;
2806
+ var _useState = React.useState(null),
2807
+ _useState2 = _typeof._slicedToArray(_useState, 2),
2808
+ resolution = _useState2[0],
2809
+ setResolution = _useState2[1];
2810
+ React.useEffect(function () {
2811
+ if (source.status === "error") {
2812
+ return;
2813
+ }
2814
+ var cancelled = false;
2815
+ asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee() {
2816
+ var valModule, next, _t;
2817
+ return asyncToGenerator._regenerator().w(function (_context) {
2818
+ while (1) switch (_context.n) {
2819
+ case 0:
2820
+ _context.n = 1;
2821
+ return internal.findValModule(valModules, source.sourcePath);
2822
+ case 1:
2823
+ valModule = _context.v;
2824
+ if (!valModule) {
2825
+ _context.n = 3;
2826
+ break;
2827
+ }
2828
+ _context.n = 2;
2829
+ return internal.resolveValComponentPreview({
2830
+ valModule: valModule,
2831
+ sourcePath: source.sourcePath,
2832
+ moduleValue: JSON.parse(source.moduleJson),
2833
+ example: example,
2834
+ props: props
2835
+ });
2836
+ case 2:
2837
+ _t = _context.v;
2838
+ _context.n = 4;
2839
+ break;
2840
+ case 3:
2841
+ _t = {
2842
+ status: "error",
2843
+ message: "No module for '".concat(source.sourcePath, "' in val.modules.")
2844
+ };
2845
+ case 4:
2846
+ next = _t;
2847
+ if (!cancelled) {
2848
+ setResolution(next);
2849
+ }
2850
+ case 5:
2851
+ return _context.a(2);
2852
+ }
2853
+ }, _callee);
2854
+ }))()["catch"](function (err) {
2855
+ if (!cancelled) {
2856
+ setResolution({
2857
+ status: "error",
2858
+ message: err instanceof Error ? err.message : String(err)
2859
+ });
2860
+ }
2861
+ });
2862
+ return function () {
2863
+ cancelled = true;
2864
+ };
2865
+ }, [valModules, source, example, props]);
2866
+ if (source.status === "error") {
2867
+ return /*#__PURE__*/jsxRuntime.jsx(internal.ValPreviewMessage, {
2868
+ children: source.message
2869
+ });
2870
+ }
2871
+ // Nothing until the first resolution, and the previous one while the next
2872
+ // is on its way, so a refresh does not flash an empty frame.
2873
+ if (resolution === null) {
2874
+ return null;
2875
+ }
2876
+ if (resolution.status === "error") {
2877
+ return /*#__PURE__*/jsxRuntime.jsx(internal.ValPreviewMessage, {
2878
+ children: resolution.message
2879
+ });
2880
+ }
2881
+ var Component = resolution.Component;
2882
+ return /*#__PURE__*/jsxRuntime.jsx(Component, _typeof._objectSpread2({}, resolution.props));
2883
+ }
2884
+
2729
2885
  function _objectWithoutPropertiesLoose(r, e) {
2730
2886
  if (null == r) return {};
2731
2887
  var t = {};
@@ -3570,14 +3726,20 @@ Object.defineProperty(exports, 'modules', {
3570
3726
  enumerable: true,
3571
3727
  get: function () { return core.modules; }
3572
3728
  });
3729
+ Object.defineProperty(exports, 'ValComponentEditor', {
3730
+ enumerable: true,
3731
+ get: function () { return internal.ValComponentEditor; }
3732
+ });
3573
3733
  Object.defineProperty(exports, 'ValRichText', {
3574
3734
  enumerable: true,
3575
3735
  get: function () { return internal.ValRichText; }
3576
3736
  });
3577
3737
  exports.Internal = Internal;
3738
+ exports.Unstable_ValComponentPreview = Unstable_ValComponentPreview;
3578
3739
  exports.ValApp = ValApp;
3579
3740
  exports.ValImage = ValImage;
3580
3741
  exports.ValModulesClient = ValModulesClient;
3742
+ exports.ValPreviewBridge = ValPreviewBridge;
3581
3743
  exports.ValProvider = ValProvider;
3582
3744
  exports.ValVideo = ValVideo;
3583
3745
  exports.initVal = initVal;