@valbuild/next 0.96.3 → 0.97.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/client/dist/valbuild-next-client.cjs.dev.js +29 -10
- package/client/dist/valbuild-next-client.cjs.prod.js +29 -10
- package/client/dist/valbuild-next-client.esm.js +29 -10
- package/dist/{ValApp-3df36e0d.cjs.dev.js → ValApp-1992d8b3.cjs.dev.js} +3 -2
- package/dist/{ValApp-e2e1dfed.esm.js → ValApp-8912fc8b.esm.js} +3 -2
- package/dist/ValApp-bb207e96.cjs.js +7 -0
- package/dist/{ValApp-22147086.cjs.prod.js → ValApp-bb207e96.cjs.prod.js} +3 -2
- package/dist/ValModulesClient-0dd601a1.esm.js +48 -0
- package/dist/ValModulesClient-10c0721c.cjs.js +7 -0
- package/dist/ValModulesClient-10c0721c.cjs.prod.js +53 -0
- package/dist/ValModulesClient-4ecabf99.cjs.dev.js +53 -0
- package/dist/{ValNextProvider-26ef0c1c.cjs.dev.js → ValNextProvider-03a9f8fd.cjs.dev.js} +103 -25
- package/dist/ValNextProvider-6103cb74.cjs.js +7 -0
- package/dist/{ValNextProvider-b0d9fa24.cjs.prod.js → ValNextProvider-6103cb74.cjs.prod.js} +103 -25
- package/dist/{ValNextProvider-e163e127.esm.js → ValNextProvider-7302b8af.esm.js} +104 -26
- package/dist/ValOverlayContext-3c37e5a7.esm.js +251 -0
- package/dist/ValOverlayContext-c6f27a6d.cjs.dev.js +262 -0
- package/dist/ValOverlayContext-f7f45bc7.cjs.js +7 -0
- package/dist/ValOverlayContext-f7f45bc7.cjs.prod.js +262 -0
- package/dist/declarations/src/ValApp.d.ts +3 -1
- package/dist/declarations/src/ValModulesClient.d.ts +38 -0
- package/dist/declarations/src/ValProvider.d.ts +1 -0
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
- package/dist/declarations/src/initVal.d.ts +25 -0
- package/dist/defineProperty-8951f469.cjs.prod.js +29 -0
- package/dist/defineProperty-cca5affa.esm.js +26 -0
- package/dist/defineProperty-f90345d7.cjs.dev.js +29 -0
- package/dist/{objectSpread2-3c87fb4f.cjs.prod.js → objectSpread2-13f847a9.cjs.prod.js} +2 -27
- package/dist/{objectSpread2-792eb2c2.cjs.dev.js → objectSpread2-58024783.cjs.dev.js} +2 -27
- package/dist/{objectSpread2-c1340c1c.esm.js → objectSpread2-60d1bd93.esm.js} +2 -25
- package/dist/{routeFromVal-ef8c304a.cjs.prod.js → routeFromVal-13c832b2.cjs.prod.js} +1 -1
- package/dist/{routeFromVal-748d2aec.esm.js → routeFromVal-8855a5cc.esm.js} +1 -1
- package/dist/{routeFromVal-8fdaa0d0.cjs.dev.js → routeFromVal-9b610e77.cjs.dev.js} +1 -1
- package/dist/valbuild-next.cjs.dev.js +56 -4
- package/dist/valbuild-next.cjs.prod.js +56 -4
- package/dist/valbuild-next.esm.js +48 -4
- package/dist/{asyncToGenerator-8e5c36c8.cjs.prod.js → version-0e6da9a7.cjs.prod.js} +10 -0
- package/dist/{asyncToGenerator-500f022f.esm.js → version-4d7b692c.esm.js} +10 -1
- package/dist/{asyncToGenerator-c3823d62.cjs.dev.js → version-c311d818.cjs.dev.js} +10 -0
- package/package.json +14 -8
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +38 -36
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +38 -36
- package/rsc/dist/valbuild-next-rsc.esm.js +7 -5
- package/server/dist/valbuild-next-server.cjs.dev.js +9 -9
- package/server/dist/valbuild-next-server.cjs.prod.js +9 -9
- package/server/dist/valbuild-next-server.esm.js +3 -3
- package/dist/ValApp-22147086.cjs.js +0 -7
- package/dist/ValNextProvider-b0d9fa24.cjs.js +0 -7
- package/dist/ValOverlayContext-6635a4d7.esm.js +0 -114
- package/dist/ValOverlayContext-942f1294.cjs.js +0 -7
- package/dist/ValOverlayContext-942f1294.cjs.prod.js +0 -125
- package/dist/ValOverlayContext-c82a4507.cjs.dev.js +0 -125
- package/dist/version-16f6b0ce.esm.js +0 -10
- package/dist/version-d034b2fc.cjs.dev.js +0 -12
- package/dist/version-d2061026.cjs.prod.js +0 -12
package/README.md
CHANGED
|
@@ -333,6 +333,39 @@ import { s } from "./val.config";
|
|
|
333
333
|
s.string().nullable(); // <- Schema<string | null>
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
+
## Description
|
|
337
|
+
|
|
338
|
+
All schema types can be given a human-readable description with `.describe(text)`. Descriptions are shown in the Val editor UI as muted helper text under the field label, helping editors understand what a field is for without leaving the page.
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
import { s } from "./val.config";
|
|
342
|
+
|
|
343
|
+
s.object({
|
|
344
|
+
name: s.string().describe("The author's full name"),
|
|
345
|
+
}).describe("Author of the blog post");
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
For records, calling `.describe()` on the **key** schema labels the record keys in the editor (useful when the key is something like an email or slug that benefits from extra context), while calling it on the **value** schema describes the entry itself.
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
s.record(
|
|
352
|
+
s.string().describe("Email"),
|
|
353
|
+
s.object({ name: s.string() }).describe("Author"),
|
|
354
|
+
);
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
`.describe()` can be combined freely with other modifiers and is preserved through `.nullable()`, `.validate()`, `.minLength()`, etc.:
|
|
358
|
+
|
|
359
|
+
```ts
|
|
360
|
+
s.string().describe("Slug").minLength(1).maxLength(64);
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Pass `null` to clear a previously set description (useful when extending a base schema):
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
s.string().describe("Original").describe(null); // no description on the resulting schema
|
|
367
|
+
```
|
|
368
|
+
|
|
336
369
|
## Array
|
|
337
370
|
|
|
338
371
|
```ts
|
|
@@ -6,11 +6,12 @@ require('client-only');
|
|
|
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
|
-
var routeFromVal = require('../../dist/routeFromVal-
|
|
9
|
+
var ValOverlayContext = require('../../dist/ValOverlayContext-c6f27a6d.cjs.dev.js');
|
|
10
|
+
var routeFromVal = require('../../dist/routeFromVal-9b610e77.cjs.dev.js');
|
|
11
11
|
require('../../dist/createForOfIteratorHelper-0445603c.cjs.dev.js');
|
|
12
12
|
require('../../dist/unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
|
|
13
|
-
require('../../dist/objectSpread2-
|
|
13
|
+
require('../../dist/objectSpread2-58024783.cjs.dev.js');
|
|
14
|
+
require('../../dist/defineProperty-f90345d7.cjs.dev.js');
|
|
14
15
|
require('../../dist/slicedToArray-44036a76.cjs.dev.js');
|
|
15
16
|
require('@valbuild/shared/internal');
|
|
16
17
|
|
|
@@ -31,6 +32,23 @@ function useValStega(selector) {
|
|
|
31
32
|
}, store ? store.getServerSnapshot(moduleIds) : function () {
|
|
32
33
|
return;
|
|
33
34
|
});
|
|
35
|
+
// Suspense gate. `suspend` is false during SSR and hydration (so the static
|
|
36
|
+
// committed source is rendered, matching the server HTML exactly) and is
|
|
37
|
+
// activated by ValProvider after hydration — inside a transition — when the
|
|
38
|
+
// `suspend` prop is set AND the Val Enable cookie is present (checked
|
|
39
|
+
// client-side; the server store is never populated). It never deactivates.
|
|
40
|
+
// The production path (no cookie) skips the call entirely. The
|
|
41
|
+
// `draftMode !== false` check is a release valve: with draft mode off the
|
|
42
|
+
// store never receives source updates, so waitForLoad could only ever
|
|
43
|
+
// resolve via its timeout — and would then re-suspend on every subsequent
|
|
44
|
+
// render since the resolved promise is evicted from the cache. draftMode is
|
|
45
|
+
// null until the first /draft/stat poll resolves; null -> true keeps
|
|
46
|
+
// suspending, -> false only unblocks, and false -> true happens only on an
|
|
47
|
+
// explicit draft-mode enable which already refreshes the route.
|
|
48
|
+
// React.use is allowed inside conditionals — it is not a hook.
|
|
49
|
+
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && store && !store.hasAllLoaded(moduleIds)) {
|
|
50
|
+
React__default["default"].use(store.waitForLoad(moduleIds));
|
|
51
|
+
}
|
|
34
52
|
return stega.stegaEncode(selector, {
|
|
35
53
|
disabled: !valOverlayContext.draftMode,
|
|
36
54
|
getModule: function getModule(moduleId) {
|
|
@@ -44,17 +62,18 @@ function resolveParams(params) {
|
|
|
44
62
|
if (!params) {
|
|
45
63
|
return null;
|
|
46
64
|
}
|
|
47
|
-
var resolvedParams = "then" in params ? undefined : params;
|
|
48
65
|
if ("then" in params) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
// Defensive guard: peerDependencies declare React >=19, but if a consumer
|
|
67
|
+
// somehow ends up on React 18 with a promise params arg, surface a
|
|
68
|
+
// diagnosable error instead of a cryptic `TypeError: React.use is not a
|
|
69
|
+
// function`. Callers treat null as the error sentinel.
|
|
70
|
+
if (!("use" in React__default["default"])) {
|
|
71
|
+
console.error("Val: useValRoute received a Promise params argument but React.use is unavailable. Upgrade to React 19+ or pre-resolve the promise before passing it.");
|
|
54
72
|
return null;
|
|
55
73
|
}
|
|
74
|
+
return React__default["default"].use(params);
|
|
56
75
|
}
|
|
57
|
-
return
|
|
76
|
+
return params;
|
|
58
77
|
}
|
|
59
78
|
function useValRouteStega(selector, params) {
|
|
60
79
|
var val = useValStega(selector);
|
|
@@ -6,11 +6,12 @@ require('client-only');
|
|
|
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
|
-
var routeFromVal = require('../../dist/routeFromVal-
|
|
9
|
+
var ValOverlayContext = require('../../dist/ValOverlayContext-f7f45bc7.cjs.prod.js');
|
|
10
|
+
var routeFromVal = require('../../dist/routeFromVal-13c832b2.cjs.prod.js');
|
|
11
11
|
require('../../dist/createForOfIteratorHelper-d4afcad8.cjs.prod.js');
|
|
12
12
|
require('../../dist/unsupportedIterableToArray-0d2087a2.cjs.prod.js');
|
|
13
|
-
require('../../dist/objectSpread2-
|
|
13
|
+
require('../../dist/objectSpread2-13f847a9.cjs.prod.js');
|
|
14
|
+
require('../../dist/defineProperty-8951f469.cjs.prod.js');
|
|
14
15
|
require('../../dist/slicedToArray-ce613de6.cjs.prod.js');
|
|
15
16
|
require('@valbuild/shared/internal');
|
|
16
17
|
|
|
@@ -31,6 +32,23 @@ function useValStega(selector) {
|
|
|
31
32
|
}, store ? store.getServerSnapshot(moduleIds) : function () {
|
|
32
33
|
return;
|
|
33
34
|
});
|
|
35
|
+
// Suspense gate. `suspend` is false during SSR and hydration (so the static
|
|
36
|
+
// committed source is rendered, matching the server HTML exactly) and is
|
|
37
|
+
// activated by ValProvider after hydration — inside a transition — when the
|
|
38
|
+
// `suspend` prop is set AND the Val Enable cookie is present (checked
|
|
39
|
+
// client-side; the server store is never populated). It never deactivates.
|
|
40
|
+
// The production path (no cookie) skips the call entirely. The
|
|
41
|
+
// `draftMode !== false` check is a release valve: with draft mode off the
|
|
42
|
+
// store never receives source updates, so waitForLoad could only ever
|
|
43
|
+
// resolve via its timeout — and would then re-suspend on every subsequent
|
|
44
|
+
// render since the resolved promise is evicted from the cache. draftMode is
|
|
45
|
+
// null until the first /draft/stat poll resolves; null -> true keeps
|
|
46
|
+
// suspending, -> false only unblocks, and false -> true happens only on an
|
|
47
|
+
// explicit draft-mode enable which already refreshes the route.
|
|
48
|
+
// React.use is allowed inside conditionals — it is not a hook.
|
|
49
|
+
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && store && !store.hasAllLoaded(moduleIds)) {
|
|
50
|
+
React__default["default"].use(store.waitForLoad(moduleIds));
|
|
51
|
+
}
|
|
34
52
|
return stega.stegaEncode(selector, {
|
|
35
53
|
disabled: !valOverlayContext.draftMode,
|
|
36
54
|
getModule: function getModule(moduleId) {
|
|
@@ -44,17 +62,18 @@ function resolveParams(params) {
|
|
|
44
62
|
if (!params) {
|
|
45
63
|
return null;
|
|
46
64
|
}
|
|
47
|
-
var resolvedParams = "then" in params ? undefined : params;
|
|
48
65
|
if ("then" in params) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
// Defensive guard: peerDependencies declare React >=19, but if a consumer
|
|
67
|
+
// somehow ends up on React 18 with a promise params arg, surface a
|
|
68
|
+
// diagnosable error instead of a cryptic `TypeError: React.use is not a
|
|
69
|
+
// function`. Callers treat null as the error sentinel.
|
|
70
|
+
if (!("use" in React__default["default"])) {
|
|
71
|
+
console.error("Val: useValRoute received a Promise params argument but React.use is unavailable. Upgrade to React 19+ or pre-resolve the promise before passing it.");
|
|
54
72
|
return null;
|
|
55
73
|
}
|
|
74
|
+
return React__default["default"].use(params);
|
|
56
75
|
}
|
|
57
|
-
return
|
|
76
|
+
return params;
|
|
58
77
|
}
|
|
59
78
|
function useValRouteStega(selector, params) {
|
|
60
79
|
var val = useValStega(selector);
|
|
@@ -2,11 +2,12 @@ import 'client-only';
|
|
|
2
2
|
import { Internal } from '@valbuild/core';
|
|
3
3
|
import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
|
|
4
4
|
import React from 'react';
|
|
5
|
-
import { useValOverlayContext } from '../../dist/ValOverlayContext-
|
|
6
|
-
import { i as initValRouteFromVal, g as getValRouteUrlFromVal } from '../../dist/routeFromVal-
|
|
5
|
+
import { useValOverlayContext } from '../../dist/ValOverlayContext-3c37e5a7.esm.js';
|
|
6
|
+
import { i as initValRouteFromVal, g as getValRouteUrlFromVal } from '../../dist/routeFromVal-8855a5cc.esm.js';
|
|
7
7
|
import '../../dist/createForOfIteratorHelper-5758a730.esm.js';
|
|
8
8
|
import '../../dist/unsupportedIterableToArray-5baabfdc.esm.js';
|
|
9
|
-
import '../../dist/objectSpread2-
|
|
9
|
+
import '../../dist/objectSpread2-60d1bd93.esm.js';
|
|
10
|
+
import '../../dist/defineProperty-cca5affa.esm.js';
|
|
10
11
|
import '../../dist/slicedToArray-aa291011.esm.js';
|
|
11
12
|
import '@valbuild/shared/internal';
|
|
12
13
|
|
|
@@ -23,6 +24,23 @@ function useValStega(selector) {
|
|
|
23
24
|
}, store ? store.getServerSnapshot(moduleIds) : function () {
|
|
24
25
|
return;
|
|
25
26
|
});
|
|
27
|
+
// Suspense gate. `suspend` is false during SSR and hydration (so the static
|
|
28
|
+
// committed source is rendered, matching the server HTML exactly) and is
|
|
29
|
+
// activated by ValProvider after hydration — inside a transition — when the
|
|
30
|
+
// `suspend` prop is set AND the Val Enable cookie is present (checked
|
|
31
|
+
// client-side; the server store is never populated). It never deactivates.
|
|
32
|
+
// The production path (no cookie) skips the call entirely. The
|
|
33
|
+
// `draftMode !== false` check is a release valve: with draft mode off the
|
|
34
|
+
// store never receives source updates, so waitForLoad could only ever
|
|
35
|
+
// resolve via its timeout — and would then re-suspend on every subsequent
|
|
36
|
+
// render since the resolved promise is evicted from the cache. draftMode is
|
|
37
|
+
// null until the first /draft/stat poll resolves; null -> true keeps
|
|
38
|
+
// suspending, -> false only unblocks, and false -> true happens only on an
|
|
39
|
+
// explicit draft-mode enable which already refreshes the route.
|
|
40
|
+
// React.use is allowed inside conditionals — it is not a hook.
|
|
41
|
+
if (valOverlayContext.suspend && valOverlayContext.draftMode !== false && store && !store.hasAllLoaded(moduleIds)) {
|
|
42
|
+
React.use(store.waitForLoad(moduleIds));
|
|
43
|
+
}
|
|
26
44
|
return stegaEncode(selector, {
|
|
27
45
|
disabled: !valOverlayContext.draftMode,
|
|
28
46
|
getModule: function getModule(moduleId) {
|
|
@@ -36,17 +54,18 @@ function resolveParams(params) {
|
|
|
36
54
|
if (!params) {
|
|
37
55
|
return null;
|
|
38
56
|
}
|
|
39
|
-
var resolvedParams = "then" in params ? undefined : params;
|
|
40
57
|
if ("then" in params) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
// Defensive guard: peerDependencies declare React >=19, but if a consumer
|
|
59
|
+
// somehow ends up on React 18 with a promise params arg, surface a
|
|
60
|
+
// diagnosable error instead of a cryptic `TypeError: React.use is not a
|
|
61
|
+
// function`. Callers treat null as the error sentinel.
|
|
62
|
+
if (!("use" in React)) {
|
|
63
|
+
console.error("Val: useValRoute received a Promise params argument but React.use is unavailable. Upgrade to React 19+ or pre-resolve the promise before passing it.");
|
|
46
64
|
return null;
|
|
47
65
|
}
|
|
66
|
+
return React.use(params);
|
|
48
67
|
}
|
|
49
|
-
return
|
|
68
|
+
return params;
|
|
50
69
|
}
|
|
51
70
|
function useValRouteStega(selector, params) {
|
|
52
71
|
var val = useValStega(selector);
|
|
@@ -18,7 +18,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
18
18
|
var Script__default = /*#__PURE__*/_interopDefault(Script);
|
|
19
19
|
|
|
20
20
|
var ValApp = function ValApp(_ref) {
|
|
21
|
-
var config = _ref.config
|
|
21
|
+
var config = _ref.config,
|
|
22
|
+
children = _ref.children;
|
|
22
23
|
var route = "/api/val"; // TODO: make configurable
|
|
23
24
|
var _useState = React.useState(),
|
|
24
25
|
_useState2 = slicedToArray._slicedToArray(_useState, 2),
|
|
@@ -134,7 +135,7 @@ var ValApp = function ValApp(_ref) {
|
|
|
134
135
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
135
136
|
id: ui.VAL_APP_ID,
|
|
136
137
|
ref: container
|
|
137
|
-
})]
|
|
138
|
+
}), children]
|
|
138
139
|
});
|
|
139
140
|
};
|
|
140
141
|
|
|
@@ -10,7 +10,8 @@ import '@valbuild/shared/internal';
|
|
|
10
10
|
import '@valbuild/core';
|
|
11
11
|
|
|
12
12
|
var ValApp = function ValApp(_ref) {
|
|
13
|
-
var config = _ref.config
|
|
13
|
+
var config = _ref.config,
|
|
14
|
+
children = _ref.children;
|
|
14
15
|
var route = "/api/val"; // TODO: make configurable
|
|
15
16
|
var _useState = useState(),
|
|
16
17
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -126,7 +127,7 @@ var ValApp = function ValApp(_ref) {
|
|
|
126
127
|
}), /*#__PURE__*/jsx("div", {
|
|
127
128
|
id: VAL_APP_ID,
|
|
128
129
|
ref: container
|
|
129
|
-
})]
|
|
130
|
+
}), children]
|
|
130
131
|
});
|
|
131
132
|
};
|
|
132
133
|
|
|
@@ -18,7 +18,8 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
18
18
|
var Script__default = /*#__PURE__*/_interopDefault(Script);
|
|
19
19
|
|
|
20
20
|
var ValApp = function ValApp(_ref) {
|
|
21
|
-
var config = _ref.config
|
|
21
|
+
var config = _ref.config,
|
|
22
|
+
children = _ref.children;
|
|
22
23
|
var route = "/api/val"; // TODO: make configurable
|
|
23
24
|
var _useState = React.useState(),
|
|
24
25
|
_useState2 = slicedToArray._slicedToArray(_useState, 2),
|
|
@@ -134,7 +135,7 @@ var ValApp = function ValApp(_ref) {
|
|
|
134
135
|
}), /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
135
136
|
id: ui.VAL_APP_ID,
|
|
136
137
|
ref: container
|
|
137
|
-
})]
|
|
138
|
+
}), children]
|
|
138
139
|
});
|
|
139
140
|
};
|
|
140
141
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
// Keep in sync with VAL_MODULES_UPDATED_EVENT in @valbuild/ui (useValModules.ts).
|
|
5
|
+
var VAL_MODULES_UPDATED_EVENT = "val-modules-updated";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registers the user's `val.modules` registry on `window.__VAL_MODULES__` so
|
|
9
|
+
* the Val editor SPA (both the `/val` app and the on-page overlay) can read it.
|
|
10
|
+
*
|
|
11
|
+
* Must be called from a Client Component that statically imports `val.modules`:
|
|
12
|
+
* the module `def` entries are function closures, so the registry cannot be
|
|
13
|
+
* passed as a prop across the Server → Client Component boundary and must be
|
|
14
|
+
* pulled into the client bundle and registered via the window global instead.
|
|
15
|
+
*
|
|
16
|
+
* Re-runs when the `modules` reference changes (e.g. on HMR) and dispatches
|
|
17
|
+
* `val-modules-updated` so the SPA picks up the new registry.
|
|
18
|
+
*/
|
|
19
|
+
function useRegisterValModules(modules) {
|
|
20
|
+
useEffect(function () {
|
|
21
|
+
window.__VAL_MODULES__ = modules;
|
|
22
|
+
window.dispatchEvent(new CustomEvent(VAL_MODULES_UPDATED_EVENT));
|
|
23
|
+
}, [modules]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Registers the user's `val.modules` registry for the Val editor SPA.
|
|
28
|
+
*
|
|
29
|
+
* Render this inside both `<ValProvider>` (root layout) and `<ValApp>` (the
|
|
30
|
+
* `/val` page), passing your `val.modules` default export. Use it from a
|
|
31
|
+
* Client Component so the registry ends up in the client bundle:
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* "use client";
|
|
35
|
+
* import { ValModulesClient } from "@valbuild/next";
|
|
36
|
+
* import valModules from "../../val.modules";
|
|
37
|
+
*
|
|
38
|
+
* export function RegisterValModules() {
|
|
39
|
+
* return <ValModulesClient modules={valModules} />;
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
function ValModulesClient(_ref) {
|
|
43
|
+
var modules = _ref.modules;
|
|
44
|
+
useRegisterValModules(modules);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { ValModulesClient, useRegisterValModules };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var React = require('react');
|
|
7
|
+
|
|
8
|
+
// Keep in sync with VAL_MODULES_UPDATED_EVENT in @valbuild/ui (useValModules.ts).
|
|
9
|
+
var VAL_MODULES_UPDATED_EVENT = "val-modules-updated";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Registers the user's `val.modules` registry on `window.__VAL_MODULES__` so
|
|
13
|
+
* the Val editor SPA (both the `/val` app and the on-page overlay) can read it.
|
|
14
|
+
*
|
|
15
|
+
* Must be called from a Client Component that statically imports `val.modules`:
|
|
16
|
+
* the module `def` entries are function closures, so the registry cannot be
|
|
17
|
+
* passed as a prop across the Server → Client Component boundary and must be
|
|
18
|
+
* pulled into the client bundle and registered via the window global instead.
|
|
19
|
+
*
|
|
20
|
+
* Re-runs when the `modules` reference changes (e.g. on HMR) and dispatches
|
|
21
|
+
* `val-modules-updated` so the SPA picks up the new registry.
|
|
22
|
+
*/
|
|
23
|
+
function useRegisterValModules(modules) {
|
|
24
|
+
React.useEffect(function () {
|
|
25
|
+
window.__VAL_MODULES__ = modules;
|
|
26
|
+
window.dispatchEvent(new CustomEvent(VAL_MODULES_UPDATED_EVENT));
|
|
27
|
+
}, [modules]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Registers the user's `val.modules` registry for the Val editor SPA.
|
|
32
|
+
*
|
|
33
|
+
* Render this inside both `<ValProvider>` (root layout) and `<ValApp>` (the
|
|
34
|
+
* `/val` page), passing your `val.modules` default export. Use it from a
|
|
35
|
+
* Client Component so the registry ends up in the client bundle:
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* "use client";
|
|
39
|
+
* import { ValModulesClient } from "@valbuild/next";
|
|
40
|
+
* import valModules from "../../val.modules";
|
|
41
|
+
*
|
|
42
|
+
* export function RegisterValModules() {
|
|
43
|
+
* return <ValModulesClient modules={valModules} />;
|
|
44
|
+
* }
|
|
45
|
+
*/
|
|
46
|
+
function ValModulesClient(_ref) {
|
|
47
|
+
var modules = _ref.modules;
|
|
48
|
+
useRegisterValModules(modules);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.ValModulesClient = ValModulesClient;
|
|
53
|
+
exports.useRegisterValModules = useRegisterValModules;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var React = require('react');
|
|
7
|
+
|
|
8
|
+
// Keep in sync with VAL_MODULES_UPDATED_EVENT in @valbuild/ui (useValModules.ts).
|
|
9
|
+
var VAL_MODULES_UPDATED_EVENT = "val-modules-updated";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Registers the user's `val.modules` registry on `window.__VAL_MODULES__` so
|
|
13
|
+
* the Val editor SPA (both the `/val` app and the on-page overlay) can read it.
|
|
14
|
+
*
|
|
15
|
+
* Must be called from a Client Component that statically imports `val.modules`:
|
|
16
|
+
* the module `def` entries are function closures, so the registry cannot be
|
|
17
|
+
* passed as a prop across the Server → Client Component boundary and must be
|
|
18
|
+
* pulled into the client bundle and registered via the window global instead.
|
|
19
|
+
*
|
|
20
|
+
* Re-runs when the `modules` reference changes (e.g. on HMR) and dispatches
|
|
21
|
+
* `val-modules-updated` so the SPA picks up the new registry.
|
|
22
|
+
*/
|
|
23
|
+
function useRegisterValModules(modules) {
|
|
24
|
+
React.useEffect(function () {
|
|
25
|
+
window.__VAL_MODULES__ = modules;
|
|
26
|
+
window.dispatchEvent(new CustomEvent(VAL_MODULES_UPDATED_EVENT));
|
|
27
|
+
}, [modules]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Registers the user's `val.modules` registry for the Val editor SPA.
|
|
32
|
+
*
|
|
33
|
+
* Render this inside both `<ValProvider>` (root layout) and `<ValApp>` (the
|
|
34
|
+
* `/val` page), passing your `val.modules` default export. Use it from a
|
|
35
|
+
* Client Component so the registry ends up in the client bundle:
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* "use client";
|
|
39
|
+
* import { ValModulesClient } from "@valbuild/next";
|
|
40
|
+
* import valModules from "../../val.modules";
|
|
41
|
+
*
|
|
42
|
+
* export function RegisterValModules() {
|
|
43
|
+
* return <ValModulesClient modules={valModules} />;
|
|
44
|
+
* }
|
|
45
|
+
*/
|
|
46
|
+
function ValModulesClient(_ref) {
|
|
47
|
+
var modules = _ref.modules;
|
|
48
|
+
useRegisterValModules(modules);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.ValModulesClient = ValModulesClient;
|
|
53
|
+
exports.useRegisterValModules = useRegisterValModules;
|