@valbuild/tanstack 0.146.3 → 0.147.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/CHANGELOG.md +66 -0
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +6 -6
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +6 -6
- package/client/dist/valbuild-tanstack-client.esm.js +4 -4
- package/demo/dist/valbuild-tanstack-demo.cjs.d.ts +2 -0
- package/demo/dist/valbuild-tanstack-demo.cjs.dev.js +105 -0
- package/demo/dist/valbuild-tanstack-demo.cjs.js +7 -0
- package/demo/dist/valbuild-tanstack-demo.cjs.prod.js +105 -0
- package/demo/dist/valbuild-tanstack-demo.esm.js +101 -0
- package/demo/package.json +4 -0
- package/dist/{ValOverlayContext-3f080cce.cjs.dev.js → ValOverlayContext-510328ec.cjs.dev.js} +17 -17
- package/dist/{ValOverlayContext-59a0b19f.esm.js → ValOverlayContext-6278320b.esm.js} +1 -1
- package/dist/{ValOverlayContext-3e2c48a6.cjs.prod.js → ValOverlayContext-d3acd157.cjs.prod.js} +17 -17
- package/dist/{version-d506fa5a.esm.js → asyncToGenerator-500f022f.esm.js} +1 -149
- package/dist/{version-2e1a465b.cjs.prod.js → asyncToGenerator-8e5c36c8.cjs.prod.js} +0 -151
- package/dist/{version-1226397e.cjs.dev.js → asyncToGenerator-c3823d62.cjs.dev.js} +0 -151
- package/dist/declarations/src/ValApp.d.ts +15 -1
- package/dist/declarations/src/ValProvider.d.ts +1 -0
- package/dist/declarations/src/demo/index.d.ts +7 -0
- package/dist/declarations/src/demo/initValDemoServer.d.ts +27 -0
- package/dist/demoServiceWorker-382e1b63.cjs.dev.js +60 -0
- package/dist/demoServiceWorker-56fd96cf.esm.js +55 -0
- package/dist/demoServiceWorker-994710f7.cjs.prod.js +60 -0
- package/dist/{routeFromVal-385ee69c.cjs.dev.js → routeFromVal-0ea4586f.cjs.dev.js} +17 -24
- package/dist/{routeFromVal-ffa948ef.cjs.prod.js → routeFromVal-97a52f43.cjs.prod.js} +17 -24
- package/dist/{routeFromVal-ae54a17e.esm.js → routeFromVal-9f1f8725.esm.js} +7 -13
- package/dist/{createForOfIteratorHelper-93a62170.esm.js → typeof-66e2d869.esm.js} +11 -1
- package/dist/{createForOfIteratorHelper-9afd7d2d.cjs.prod.js → typeof-8998e126.cjs.prod.js} +11 -0
- package/dist/{createForOfIteratorHelper-4497beef.cjs.dev.js → typeof-dd0246a1.cjs.dev.js} +11 -0
- package/dist/valbuild-tanstack.cjs.dev.js +390 -43
- package/dist/valbuild-tanstack.cjs.prod.js +390 -43
- package/dist/valbuild-tanstack.esm.js +356 -9
- package/dist/version-1ae7092b.esm.js +174 -0
- package/dist/version-83d7f4b7.cjs.prod.js +179 -0
- package/dist/version-a820698f.cjs.dev.js +179 -0
- package/package.json +16 -10
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +60 -75
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +60 -75
- package/server/dist/valbuild-tanstack-server.esm.js +4 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,71 @@
|
|
|
1
1
|
# @valbuild/tanstack
|
|
2
2
|
|
|
3
|
+
## 0.147.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#816](https://github.com/valbuild/val/pull/816) [`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b) Thanks [@freekh](https://github.com/freekh)! - Routers can give each route parameter a schema, and a URL can say which language a page is in.
|
|
8
|
+
|
|
9
|
+
- **`s.router(router, params, item)`** takes a schema per route parameter, by the name the route file gives it (`$slug`, `[slug]`, `{-$locale}`). Each key's parameters are validated against them, and a name the route does not have is a schema error.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
s.router(tanstackRouter, { locale: urlLocale, slug: s.string() }, item);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- **`s.enum(...).locales({ ... })`** says which of the project's languages each value means, so `/nb/…` can mean `nb-NO`. The tags are checked against `locales.available` in the settings module, like `s.locale()`. On a nullable enum, a second argument names the language of a URL that leaves the segment out, which only a router parameter may use:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const urlLocale = s
|
|
19
|
+
.enum("nb")
|
|
20
|
+
.nullable()
|
|
21
|
+
.locales({ nb: "nb-NO" }, { null: "en-US" });
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
A router with a locale parameter makes each page a locale scope, so the Studio and validation know which language every page is in.
|
|
25
|
+
|
|
26
|
+
- **A route's language segment can no longer be forgotten.** In a project that declares `locales.available`, a page route with a `locale` or `lang` segment (`{-$locale}`, `[lang]`) whose module gives that parameter no schema is reported, saying what to add. Any schema answers it, so a `$lang` that is not a language is silenced with its own, e.g. `{ lang: s.enum("typescript", "python") }`. It is an ordinary validation error: the Studio still opens and `val validate` lists it, but a project that already has such a route will see it after upgrading, and it blocks publishing until the parameter has a schema.
|
|
27
|
+
- **The Studio's new-page form offers a language as a list.** A route parameter whose schema is a locale is picked from the project's languages, each named in its own language, with "no prefix" where the URL may leave the segment out. Other enum parameters get a list of their values, and every parameter's description is shown under it. The URL row previews what the choice puts there.
|
|
28
|
+
- **TanStack optional segments (`{-$param}`)** are now understood: route validation, `useValRoute` and the Studio's new-page form accept keys with and without the segment.
|
|
29
|
+
|
|
30
|
+
- [#876](https://github.com/valbuild/val/pull/876) [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd) Thanks [@freekh](https://github.com/freekh)! - Demo mode: run the Val Studio with no account and no backend (TanStack Start).
|
|
31
|
+
|
|
32
|
+
`<ValApp demo>` starts Val's own server in the visitor's browser tab, and the Studio talks to it there instead of to `/api/val`. Edits show up in the page as they are typed and are held in the tab's memory: nothing is sent anywhere, and a reload starts over. Images and videos can be uploaded too: a small service worker, served by `initValDemoServer()`, hands the upload and the unpublished files to the server in the tab, so an uploaded photo or video shows in the page with nothing leaving the browser. Uploads are capped by their size after encoding. Pair `<ValApp demo>` with `<ValProvider demo>` on the site and `initValDemoServer()` from the new `@valbuild/tanstack/demo` entry on the API route. In a demo the Studio opens with a guided tour, Publish explains what it would do instead of publishing, and Preview in a new tab is shown but disabled.
|
|
33
|
+
|
|
34
|
+
Also:
|
|
35
|
+
|
|
36
|
+
- `@valbuild/server/browser` is a new entry: Val's request handling, bundleable for a browser. The TypeScript compiler, which only publishing and history need, is loaded when they ask for it, so a browser bundle of the server is about 140 KB rather than 3.6 MB.
|
|
37
|
+
- `s.image({ encode })` now scales an image down in browsers that cannot write WebP (Safari), as a JPEG or PNG in the image's own format, instead of uploading it at full size.
|
|
38
|
+
- `GET /profiles` answers with no profiles, rather than an error, when edits are stored locally and no project is configured.
|
|
39
|
+
|
|
40
|
+
### Patch Changes
|
|
41
|
+
|
|
42
|
+
- Updated dependencies [[`2f09cd5`](https://github.com/valbuild/val/commit/2f09cd5e2f4fc37f06917899f24f9ad2ee8d3a8b), [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd), [`cb04e58`](https://github.com/valbuild/val/commit/cb04e586db1e3ffd20ec1fee744561b1c8f8cffd)]:
|
|
43
|
+
- @valbuild/core@0.147.0
|
|
44
|
+
- @valbuild/shared@0.147.0
|
|
45
|
+
- @valbuild/ui@0.147.0
|
|
46
|
+
- @valbuild/server@0.147.0
|
|
47
|
+
- @valbuild/language-server@0.147.0
|
|
48
|
+
- @valbuild/mcp@0.147.0
|
|
49
|
+
- @valbuild/react@0.147.0
|
|
50
|
+
|
|
51
|
+
## 0.146.4
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- [#870](https://github.com/valbuild/val/pull/870) [`81f2e80`](https://github.com/valbuild/val/commit/81f2e803c4cefdf58bbe6856c06e98ace95a8e0b) Thanks [@freekh](https://github.com/freekh)! - The canvas works on a page behind your site's own login.
|
|
56
|
+
|
|
57
|
+
A site with its own sign-in (a dashboard, an intranet, a members' area) can be edited in the canvas. The canvas is a frame on the same origin as the Studio, so it sends your site's cookies like any other tab: if you are signed in to the site, the canvas shows the page signed in as you.
|
|
58
|
+
|
|
59
|
+
If you were not signed in, the site redirected the canvas to its login page, and the canvas then broke. That page mounted Val's whole overlay inside the canvas, a Studio inside the Studio. The canvas stayed on "Preview is not ready yet" through the sign-in and after it, until you pressed Reload. Now a page shown in the Studio's canvas counts as the canvas wherever it navigated to, so you can sign in inside the canvas and keep editing.
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [[`81f2e80`](https://github.com/valbuild/val/commit/81f2e803c4cefdf58bbe6856c06e98ace95a8e0b), [`59ff6c3`](https://github.com/valbuild/val/commit/59ff6c367bc313b2bb7718b00c1641aaccab949d), [`c31f609`](https://github.com/valbuild/val/commit/c31f609fdeed79aa0e139fa4f652ba0684e96ea3)]:
|
|
62
|
+
- @valbuild/shared@0.146.4
|
|
63
|
+
- @valbuild/ui@0.146.4
|
|
64
|
+
- @valbuild/server@0.146.4
|
|
65
|
+
- @valbuild/language-server@0.146.4
|
|
66
|
+
- @valbuild/mcp@0.146.4
|
|
67
|
+
- @valbuild/react@0.146.4
|
|
68
|
+
|
|
3
69
|
## 0.146.3
|
|
4
70
|
|
|
5
71
|
### Patch Changes
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _typeof = require('../../dist/typeof-dd0246a1.cjs.dev.js');
|
|
6
6
|
var core = require('@valbuild/core');
|
|
7
7
|
var stega = require('@valbuild/react/stega');
|
|
8
8
|
var React = require('react');
|
|
9
|
-
var ValOverlayContext = require('../../dist/ValOverlayContext-
|
|
10
|
-
require('../../dist/
|
|
11
|
-
require('@valbuild/shared/client');
|
|
9
|
+
var ValOverlayContext = require('../../dist/ValOverlayContext-510328ec.cjs.dev.js');
|
|
10
|
+
var routeFromVal = require('../../dist/routeFromVal-0ea4586f.cjs.dev.js');
|
|
12
11
|
require('@valbuild/core/patch');
|
|
13
12
|
require('react/jsx-runtime');
|
|
13
|
+
require('@valbuild/shared/client');
|
|
14
14
|
|
|
15
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
16
16
|
|
|
@@ -205,7 +205,7 @@ function draftJsonEntry(draftSource, key) {
|
|
|
205
205
|
status: "absent"
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
if (draftSource === undefined ||
|
|
208
|
+
if (draftSource === undefined || _typeof._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
|
|
209
209
|
return {
|
|
210
210
|
status: "unavailable"
|
|
211
211
|
};
|
|
@@ -292,7 +292,7 @@ function useValKeyStega(selector, key) {
|
|
|
292
292
|
*/
|
|
293
293
|
function readCommittedJsonEntry(selector, key) {
|
|
294
294
|
var source = selector && core.Internal.getSource(selector);
|
|
295
|
-
var marker = source &&
|
|
295
|
+
var marker = source && _typeof._typeof(source) === "object" ? source[key] : undefined;
|
|
296
296
|
if (!core.Internal.isJson(marker)) {
|
|
297
297
|
return undefined;
|
|
298
298
|
}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _typeof = require('../../dist/typeof-8998e126.cjs.prod.js');
|
|
6
6
|
var core = require('@valbuild/core');
|
|
7
7
|
var stega = require('@valbuild/react/stega');
|
|
8
8
|
var React = require('react');
|
|
9
|
-
var ValOverlayContext = require('../../dist/ValOverlayContext-
|
|
10
|
-
require('../../dist/
|
|
11
|
-
require('@valbuild/shared/client');
|
|
9
|
+
var ValOverlayContext = require('../../dist/ValOverlayContext-d3acd157.cjs.prod.js');
|
|
10
|
+
var routeFromVal = require('../../dist/routeFromVal-97a52f43.cjs.prod.js');
|
|
12
11
|
require('@valbuild/core/patch');
|
|
13
12
|
require('react/jsx-runtime');
|
|
13
|
+
require('@valbuild/shared/client');
|
|
14
14
|
|
|
15
15
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
16
16
|
|
|
@@ -205,7 +205,7 @@ function draftJsonEntry(draftSource, key) {
|
|
|
205
205
|
status: "absent"
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
|
-
if (draftSource === undefined ||
|
|
208
|
+
if (draftSource === undefined || _typeof._typeof(draftSource) !== "object" || Array.isArray(draftSource)) {
|
|
209
209
|
return {
|
|
210
210
|
status: "unavailable"
|
|
211
211
|
};
|
|
@@ -292,7 +292,7 @@ function useValKeyStega(selector, key) {
|
|
|
292
292
|
*/
|
|
293
293
|
function readCommittedJsonEntry(selector, key) {
|
|
294
294
|
var source = selector && core.Internal.getSource(selector);
|
|
295
|
-
var marker = source &&
|
|
295
|
+
var marker = source && _typeof._typeof(source) === "object" ? source[key] : undefined;
|
|
296
296
|
if (!core.Internal.isJson(marker)) {
|
|
297
297
|
return undefined;
|
|
298
298
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as _typeof } from '../../dist/typeof-66e2d869.esm.js';
|
|
2
2
|
import { Internal } from '@valbuild/core';
|
|
3
3
|
import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { u as useValOverlayContext } from '../../dist/ValOverlayContext-
|
|
6
|
-
import '../../dist/
|
|
7
|
-
import '@valbuild/shared/client';
|
|
5
|
+
import { u as useValOverlayContext } from '../../dist/ValOverlayContext-6278320b.esm.js';
|
|
6
|
+
import { j as jsonValuesRecordToFill, f as fillJsonValuesRecord, g as getJsonEntryStegaRoot, b as bundledJsonEntryImport, i as isJsonValuesRecordSchema, a as getValRouteUrlFromVal, c as initValRouteFromVal } from '../../dist/routeFromVal-9f1f8725.esm.js';
|
|
8
7
|
import '@valbuild/core/patch';
|
|
9
8
|
import 'react/jsx-runtime';
|
|
9
|
+
import '@valbuild/shared/client';
|
|
10
10
|
|
|
11
11
|
var subscribeNever = function subscribeNever() {
|
|
12
12
|
return function () {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export * from "../../dist/declarations/src/demo/index.js";
|
|
2
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsYnVpbGQtdGFuc3RhY2stZGVtby5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL2Rpc3QvZGVjbGFyYXRpb25zL3NyYy9kZW1vL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var asyncToGenerator = require('../../dist/asyncToGenerator-c3823d62.cjs.dev.js');
|
|
6
|
+
var server = require('@valbuild/ui/server');
|
|
7
|
+
var demoServiceWorker = require('../../dist/demoServiceWorker-382e1b63.cjs.dev.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The server half of a Val demo: the Studio's own files and the demo's service
|
|
11
|
+
* worker, and nothing else.
|
|
12
|
+
*
|
|
13
|
+
* In a demo the Studio runs Val's API in the visitor's tab
|
|
14
|
+
* (`@valbuild/server/browser`, started by `<ValApp demo>`), so the app has no
|
|
15
|
+
* content or patch endpoint at all -- nothing to authenticate, nothing to
|
|
16
|
+
* abuse. What it still serves is the Studio's scripts and styles, which the
|
|
17
|
+
* page loads from `/api/val/static/...`.
|
|
18
|
+
*
|
|
19
|
+
* Its own entry, `@valbuild/tanstack/demo`, rather than beside
|
|
20
|
+
* `initValServer`: importing Val's server loads all of it -- the TypeScript
|
|
21
|
+
* compiler included -- and a demo's server needs none of it.
|
|
22
|
+
*
|
|
23
|
+
* Mount it where `initValServer`'s handler would go:
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // src/routes/api/val.$.ts
|
|
27
|
+
* import { initValDemoServer } from "@valbuild/tanstack/demo";
|
|
28
|
+
* const { valApiHandler } = initValDemoServer();
|
|
29
|
+
* export const Route = createFileRoute("/api/val/$")({
|
|
30
|
+
* server: { handlers: { GET: ({ request }) => valApiHandler(request) } },
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
function initValDemoServer() {
|
|
34
|
+
var route = "/api/val";
|
|
35
|
+
var uiRequestHandler = server.createUIRequestHandler();
|
|
36
|
+
var valApiHandler = /*#__PURE__*/function () {
|
|
37
|
+
var _ref = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee(req) {
|
|
38
|
+
var url, path, _t;
|
|
39
|
+
return asyncToGenerator._regenerator().w(function (_context) {
|
|
40
|
+
while (1) switch (_context.n) {
|
|
41
|
+
case 0:
|
|
42
|
+
url = new URL(req.url);
|
|
43
|
+
path = url.pathname.startsWith(route) ? url.pathname.slice(route.length) : null;
|
|
44
|
+
if (!(path === demoServiceWorker.DEMO_SERVICE_WORKER_PATH)) {
|
|
45
|
+
_context.n = 1;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return _context.a(2, new Response(demoServiceWorker.DEMO_SERVICE_WORKER_SOURCE, {
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "text/javascript; charset=utf-8",
|
|
51
|
+
"Service-Worker-Allowed": "/",
|
|
52
|
+
"Cache-Control": "no-cache"
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
case 1:
|
|
56
|
+
if (!(path !== null && path.startsWith("/static"))) {
|
|
57
|
+
_context.n = 3;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
_t = toResponse;
|
|
61
|
+
_context.n = 2;
|
|
62
|
+
return uiRequestHandler(path.slice("/static".length), url.href);
|
|
63
|
+
case 2:
|
|
64
|
+
return _context.a(2, _t(_context.v));
|
|
65
|
+
case 3:
|
|
66
|
+
return _context.a(2, toResponse({
|
|
67
|
+
status: 404,
|
|
68
|
+
json: {
|
|
69
|
+
message: "Val's API is not served here: this is a demo, and the Studio runs it in the browser."
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}, _callee);
|
|
74
|
+
}));
|
|
75
|
+
return function valApiHandler(_x) {
|
|
76
|
+
return _ref.apply(this, arguments);
|
|
77
|
+
};
|
|
78
|
+
}();
|
|
79
|
+
return {
|
|
80
|
+
valApiHandler: valApiHandler
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function toResponse(valRes) {
|
|
84
|
+
var headers = new Headers();
|
|
85
|
+
var valResHeaders = "headers" in valRes && valRes.headers || {};
|
|
86
|
+
for (var key in valResHeaders) {
|
|
87
|
+
var value = valResHeaders[key];
|
|
88
|
+
if (typeof value === "string") {
|
|
89
|
+
headers.set(key, value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if ("json" in valRes) {
|
|
93
|
+
headers.set("Content-Type", "application/json");
|
|
94
|
+
return new Response(JSON.stringify(valRes.json), {
|
|
95
|
+
headers: headers,
|
|
96
|
+
status: valRes.status
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return new Response("body" in valRes ? valRes.body : null, {
|
|
100
|
+
headers: headers,
|
|
101
|
+
status: valRes.status
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.initValDemoServer = initValDemoServer;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var asyncToGenerator = require('../../dist/asyncToGenerator-8e5c36c8.cjs.prod.js');
|
|
6
|
+
var server = require('@valbuild/ui/server');
|
|
7
|
+
var demoServiceWorker = require('../../dist/demoServiceWorker-994710f7.cjs.prod.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The server half of a Val demo: the Studio's own files and the demo's service
|
|
11
|
+
* worker, and nothing else.
|
|
12
|
+
*
|
|
13
|
+
* In a demo the Studio runs Val's API in the visitor's tab
|
|
14
|
+
* (`@valbuild/server/browser`, started by `<ValApp demo>`), so the app has no
|
|
15
|
+
* content or patch endpoint at all -- nothing to authenticate, nothing to
|
|
16
|
+
* abuse. What it still serves is the Studio's scripts and styles, which the
|
|
17
|
+
* page loads from `/api/val/static/...`.
|
|
18
|
+
*
|
|
19
|
+
* Its own entry, `@valbuild/tanstack/demo`, rather than beside
|
|
20
|
+
* `initValServer`: importing Val's server loads all of it -- the TypeScript
|
|
21
|
+
* compiler included -- and a demo's server needs none of it.
|
|
22
|
+
*
|
|
23
|
+
* Mount it where `initValServer`'s handler would go:
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // src/routes/api/val.$.ts
|
|
27
|
+
* import { initValDemoServer } from "@valbuild/tanstack/demo";
|
|
28
|
+
* const { valApiHandler } = initValDemoServer();
|
|
29
|
+
* export const Route = createFileRoute("/api/val/$")({
|
|
30
|
+
* server: { handlers: { GET: ({ request }) => valApiHandler(request) } },
|
|
31
|
+
* });
|
|
32
|
+
*/
|
|
33
|
+
function initValDemoServer() {
|
|
34
|
+
var route = "/api/val";
|
|
35
|
+
var uiRequestHandler = server.createUIRequestHandler();
|
|
36
|
+
var valApiHandler = /*#__PURE__*/function () {
|
|
37
|
+
var _ref = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee(req) {
|
|
38
|
+
var url, path, _t;
|
|
39
|
+
return asyncToGenerator._regenerator().w(function (_context) {
|
|
40
|
+
while (1) switch (_context.n) {
|
|
41
|
+
case 0:
|
|
42
|
+
url = new URL(req.url);
|
|
43
|
+
path = url.pathname.startsWith(route) ? url.pathname.slice(route.length) : null;
|
|
44
|
+
if (!(path === demoServiceWorker.DEMO_SERVICE_WORKER_PATH)) {
|
|
45
|
+
_context.n = 1;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
return _context.a(2, new Response(demoServiceWorker.DEMO_SERVICE_WORKER_SOURCE, {
|
|
49
|
+
headers: {
|
|
50
|
+
"Content-Type": "text/javascript; charset=utf-8",
|
|
51
|
+
"Service-Worker-Allowed": "/",
|
|
52
|
+
"Cache-Control": "no-cache"
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
case 1:
|
|
56
|
+
if (!(path !== null && path.startsWith("/static"))) {
|
|
57
|
+
_context.n = 3;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
_t = toResponse;
|
|
61
|
+
_context.n = 2;
|
|
62
|
+
return uiRequestHandler(path.slice("/static".length), url.href);
|
|
63
|
+
case 2:
|
|
64
|
+
return _context.a(2, _t(_context.v));
|
|
65
|
+
case 3:
|
|
66
|
+
return _context.a(2, toResponse({
|
|
67
|
+
status: 404,
|
|
68
|
+
json: {
|
|
69
|
+
message: "Val's API is not served here: this is a demo, and the Studio runs it in the browser."
|
|
70
|
+
}
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
}, _callee);
|
|
74
|
+
}));
|
|
75
|
+
return function valApiHandler(_x) {
|
|
76
|
+
return _ref.apply(this, arguments);
|
|
77
|
+
};
|
|
78
|
+
}();
|
|
79
|
+
return {
|
|
80
|
+
valApiHandler: valApiHandler
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function toResponse(valRes) {
|
|
84
|
+
var headers = new Headers();
|
|
85
|
+
var valResHeaders = "headers" in valRes && valRes.headers || {};
|
|
86
|
+
for (var key in valResHeaders) {
|
|
87
|
+
var value = valResHeaders[key];
|
|
88
|
+
if (typeof value === "string") {
|
|
89
|
+
headers.set(key, value);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if ("json" in valRes) {
|
|
93
|
+
headers.set("Content-Type", "application/json");
|
|
94
|
+
return new Response(JSON.stringify(valRes.json), {
|
|
95
|
+
headers: headers,
|
|
96
|
+
status: valRes.status
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return new Response("body" in valRes ? valRes.body : null, {
|
|
100
|
+
headers: headers,
|
|
101
|
+
status: valRes.status
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.initValDemoServer = initValDemoServer;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { _ as _asyncToGenerator, a as _regenerator } from '../../dist/asyncToGenerator-500f022f.esm.js';
|
|
2
|
+
import { createUIRequestHandler } from '@valbuild/ui/server';
|
|
3
|
+
import { a as DEMO_SERVICE_WORKER_PATH, c as DEMO_SERVICE_WORKER_SOURCE } from '../../dist/demoServiceWorker-56fd96cf.esm.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The server half of a Val demo: the Studio's own files and the demo's service
|
|
7
|
+
* worker, and nothing else.
|
|
8
|
+
*
|
|
9
|
+
* In a demo the Studio runs Val's API in the visitor's tab
|
|
10
|
+
* (`@valbuild/server/browser`, started by `<ValApp demo>`), so the app has no
|
|
11
|
+
* content or patch endpoint at all -- nothing to authenticate, nothing to
|
|
12
|
+
* abuse. What it still serves is the Studio's scripts and styles, which the
|
|
13
|
+
* page loads from `/api/val/static/...`.
|
|
14
|
+
*
|
|
15
|
+
* Its own entry, `@valbuild/tanstack/demo`, rather than beside
|
|
16
|
+
* `initValServer`: importing Val's server loads all of it -- the TypeScript
|
|
17
|
+
* compiler included -- and a demo's server needs none of it.
|
|
18
|
+
*
|
|
19
|
+
* Mount it where `initValServer`'s handler would go:
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // src/routes/api/val.$.ts
|
|
23
|
+
* import { initValDemoServer } from "@valbuild/tanstack/demo";
|
|
24
|
+
* const { valApiHandler } = initValDemoServer();
|
|
25
|
+
* export const Route = createFileRoute("/api/val/$")({
|
|
26
|
+
* server: { handlers: { GET: ({ request }) => valApiHandler(request) } },
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
function initValDemoServer() {
|
|
30
|
+
var route = "/api/val";
|
|
31
|
+
var uiRequestHandler = createUIRequestHandler();
|
|
32
|
+
var valApiHandler = /*#__PURE__*/function () {
|
|
33
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(req) {
|
|
34
|
+
var url, path, _t;
|
|
35
|
+
return _regenerator().w(function (_context) {
|
|
36
|
+
while (1) switch (_context.n) {
|
|
37
|
+
case 0:
|
|
38
|
+
url = new URL(req.url);
|
|
39
|
+
path = url.pathname.startsWith(route) ? url.pathname.slice(route.length) : null;
|
|
40
|
+
if (!(path === DEMO_SERVICE_WORKER_PATH)) {
|
|
41
|
+
_context.n = 1;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
return _context.a(2, new Response(DEMO_SERVICE_WORKER_SOURCE, {
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "text/javascript; charset=utf-8",
|
|
47
|
+
"Service-Worker-Allowed": "/",
|
|
48
|
+
"Cache-Control": "no-cache"
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
case 1:
|
|
52
|
+
if (!(path !== null && path.startsWith("/static"))) {
|
|
53
|
+
_context.n = 3;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
_t = toResponse;
|
|
57
|
+
_context.n = 2;
|
|
58
|
+
return uiRequestHandler(path.slice("/static".length), url.href);
|
|
59
|
+
case 2:
|
|
60
|
+
return _context.a(2, _t(_context.v));
|
|
61
|
+
case 3:
|
|
62
|
+
return _context.a(2, toResponse({
|
|
63
|
+
status: 404,
|
|
64
|
+
json: {
|
|
65
|
+
message: "Val's API is not served here: this is a demo, and the Studio runs it in the browser."
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}));
|
|
71
|
+
return function valApiHandler(_x) {
|
|
72
|
+
return _ref.apply(this, arguments);
|
|
73
|
+
};
|
|
74
|
+
}();
|
|
75
|
+
return {
|
|
76
|
+
valApiHandler: valApiHandler
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function toResponse(valRes) {
|
|
80
|
+
var headers = new Headers();
|
|
81
|
+
var valResHeaders = "headers" in valRes && valRes.headers || {};
|
|
82
|
+
for (var key in valResHeaders) {
|
|
83
|
+
var value = valResHeaders[key];
|
|
84
|
+
if (typeof value === "string") {
|
|
85
|
+
headers.set(key, value);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if ("json" in valRes) {
|
|
89
|
+
headers.set("Content-Type", "application/json");
|
|
90
|
+
return new Response(JSON.stringify(valRes.json), {
|
|
91
|
+
headers: headers,
|
|
92
|
+
status: valRes.status
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return new Response("body" in valRes ? valRes.body : null, {
|
|
96
|
+
headers: headers,
|
|
97
|
+
status: valRes.status
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { initValDemoServer };
|
package/dist/{ValOverlayContext-3f080cce.cjs.dev.js → ValOverlayContext-510328ec.cjs.dev.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _typeof = require('./typeof-dd0246a1.cjs.dev.js');
|
|
4
4
|
var patch = require('@valbuild/core/patch');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
@@ -16,7 +16,7 @@ function _classCallCheck(a, n) {
|
|
|
16
16
|
function _defineProperties(e, r) {
|
|
17
17
|
for (var t = 0; t < r.length; t++) {
|
|
18
18
|
var o = r[t];
|
|
19
|
-
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e,
|
|
19
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _typeof._toPropertyKey(o.key), o);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
function _createClass(e, r, t) {
|
|
@@ -30,20 +30,20 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
30
30
|
function ValExternalStore() {
|
|
31
31
|
var _this = this;
|
|
32
32
|
_classCallCheck(this, ValExternalStore);
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
_typeof._defineProperty(this, "listeners", void 0);
|
|
34
|
+
_typeof._defineProperty(this, "loadPromises", void 0);
|
|
35
35
|
// Path-keyed cache of every source seen via update(). The single source of
|
|
36
36
|
// truth: load state and snapshots are both derived from this, so data can be
|
|
37
37
|
// queried for any combination of paths even before a subscriber registers.
|
|
38
|
-
|
|
38
|
+
_typeof._defineProperty(this, "loadedSources", void 0);
|
|
39
39
|
// Reference-stable per-subscriberId snapshot cache for useSyncExternalStore.
|
|
40
40
|
// Built lazily from loadedSources in get() and invalidated in update().
|
|
41
|
-
|
|
41
|
+
_typeof._defineProperty(this, "snapshots", void 0);
|
|
42
42
|
// One-shot listeners used solely by waitForLoad. Kept separate from the
|
|
43
43
|
// useSyncExternalStore listeners so waitForLoad never has to register (and
|
|
44
44
|
// leak) a subscriberId.
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
_typeof._defineProperty(this, "loadListeners", void 0);
|
|
46
|
+
_typeof._defineProperty(this, "subscribe", function (paths) {
|
|
47
47
|
return function (listener) {
|
|
48
48
|
var subscriberId = createSubscriberId(paths);
|
|
49
49
|
var existing = _this.listeners.get(subscriberId);
|
|
@@ -61,17 +61,17 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
61
61
|
};
|
|
62
62
|
};
|
|
63
63
|
});
|
|
64
|
-
|
|
64
|
+
_typeof._defineProperty(this, "getSnapshot", function (paths) {
|
|
65
65
|
return function () {
|
|
66
66
|
return _this.get(paths);
|
|
67
67
|
};
|
|
68
68
|
});
|
|
69
|
-
|
|
69
|
+
_typeof._defineProperty(this, "getServerSnapshot", function (paths) {
|
|
70
70
|
return function () {
|
|
71
71
|
return _this.get(paths);
|
|
72
72
|
};
|
|
73
73
|
});
|
|
74
|
-
|
|
74
|
+
_typeof._defineProperty(this, "get", function (paths) {
|
|
75
75
|
var subscriberId = createSubscriberId(paths);
|
|
76
76
|
if (_this.snapshots.has(subscriberId)) {
|
|
77
77
|
return _this.snapshots.get(subscriberId);
|
|
@@ -80,7 +80,7 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
80
80
|
// before this subscriber registered is still returned. Cache it for a
|
|
81
81
|
// reference-stable result (required by useSyncExternalStore).
|
|
82
82
|
var record;
|
|
83
|
-
var _iterator =
|
|
83
|
+
var _iterator = _typeof._createForOfIteratorHelper(paths),
|
|
84
84
|
_step;
|
|
85
85
|
try {
|
|
86
86
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
@@ -102,8 +102,8 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
102
102
|
_this.snapshots.set(subscriberId, record);
|
|
103
103
|
return record;
|
|
104
104
|
});
|
|
105
|
-
|
|
106
|
-
var _iterator2 =
|
|
105
|
+
_typeof._defineProperty(this, "hasAllLoaded", function (paths) {
|
|
106
|
+
var _iterator2 = _typeof._createForOfIteratorHelper(paths),
|
|
107
107
|
_step2;
|
|
108
108
|
try {
|
|
109
109
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
@@ -131,7 +131,7 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
131
131
|
* hang it resolves anyway after `LOAD_TIMEOUT_MS`, logging an error so the
|
|
132
132
|
* failure is diagnosable while the page still renders with partial data.
|
|
133
133
|
*/
|
|
134
|
-
|
|
134
|
+
_typeof._defineProperty(this, "waitForLoad", function (paths) {
|
|
135
135
|
if (_this.hasAllLoaded(paths)) {
|
|
136
136
|
return Promise.resolve();
|
|
137
137
|
}
|
|
@@ -218,7 +218,7 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
218
218
|
this.snapshots["delete"](subscriberId);
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
var _iterator3 =
|
|
221
|
+
var _iterator3 = _typeof._createForOfIteratorHelper(this.listeners.keys()),
|
|
222
222
|
_step3;
|
|
223
223
|
try {
|
|
224
224
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
@@ -242,7 +242,7 @@ var ValExternalStore = /*#__PURE__*/function () {
|
|
|
242
242
|
key: "emitChange",
|
|
243
243
|
value: function emitChange(subscriberId) {
|
|
244
244
|
var _this$listeners$get;
|
|
245
|
-
var _iterator4 =
|
|
245
|
+
var _iterator4 = _typeof._createForOfIteratorHelper((_this$listeners$get = this.listeners.get(subscriberId)) !== null && _this$listeners$get !== void 0 ? _this$listeners$get : []),
|
|
246
246
|
_step4;
|
|
247
247
|
try {
|
|
248
248
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { f as _toPropertyKey, b as _createForOfIteratorHelper, g as _defineProperty } from './typeof-66e2d869.esm.js';
|
|
2
2
|
import { deepEqual } from '@valbuild/core/patch';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|