@valbuild/tanstack 0.154.0 → 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 +78 -0
- package/README.md +114 -0
- package/dist/declarations/src/ValComponentPreview.d.ts +28 -0
- package/dist/declarations/src/ValPreviewBridge.d.ts +27 -0
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +4 -0
- package/dist/declarations/src/server/fetchValPreviewSource.d.ts +34 -0
- package/dist/declarations/src/server/index.d.ts +3 -2
- package/dist/declarations/src/server/initValContent.d.ts +14 -8
- package/dist/declarations/src/server/initValMcp.d.ts +8 -1
- package/dist/declarations/src/server/initValServer.d.ts +1 -1
- package/dist/valbuild-tanstack.cjs.dev.js +164 -2
- package/dist/valbuild-tanstack.cjs.prod.js +164 -2
- package/dist/valbuild-tanstack.esm.js +163 -7
- package/dist/{version-208d50df.cjs.dev.js → version-1387cb76.cjs.dev.js} +1 -1
- package/dist/{version-59dbc545.esm.js → version-909919be.esm.js} +1 -1
- package/dist/{version-961b447c.cjs.prod.js → version-fdcad756.cjs.prod.js} +1 -1
- package/package.json +8 -8
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +342 -133
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +342 -133
- package/server/dist/valbuild-tanstack-server.esm.js +342 -134
|
@@ -6,7 +6,7 @@ var asyncToGenerator = require('./asyncToGenerator-8e5c36c8.cjs.prod.js');
|
|
|
6
6
|
var _typeof = require('./typeof-56656438.cjs.prod.js');
|
|
7
7
|
var core = require('@valbuild/core');
|
|
8
8
|
var stega = require('@valbuild/react/stega');
|
|
9
|
-
var version = require('./version-
|
|
9
|
+
var version = require('./version-fdcad756.cjs.prod.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: [
|
|
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;
|
|
@@ -5,14 +5,14 @@ import * as core from '@valbuild/core';
|
|
|
5
5
|
export { core as expr };
|
|
6
6
|
export { GenericSelector, Schema, VAL_EXTENSION, derefPatch, modules } from '@valbuild/core';
|
|
7
7
|
import { stegaEncode, stegaDecodeStrings, attrs, raw, isReactDevelopmentBuild, watchStegaLeaks, stegaLeakMessage, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX } from '@valbuild/react/stega';
|
|
8
|
-
import { r as readValEnableCookie, V as VERSION$1 } from './version-
|
|
9
|
-
import { isDraft, windowCodeChangedReporter, createDraftStore, draftHolds, draftHoldsVersions, startRefreshLoop, dispatchCodeChanged, applyValEvent } from '@valbuild/react/internal';
|
|
10
|
-
export { ValRichText } from '@valbuild/react/internal';
|
|
8
|
+
import { r as readValEnableCookie, V as VERSION$1 } from './version-909919be.esm.js';
|
|
9
|
+
import { isDraft, windowCodeChangedReporter, createDraftStore, draftHolds, draftHoldsVersions, startRefreshLoop, dispatchCodeChanged, applyValEvent, ValPreviewBridgeCore, ValPreviewMessage, resolveValComponentPreview, findValModule } from '@valbuild/react/internal';
|
|
10
|
+
export { ValComponentEditor, ValRichText } from '@valbuild/react/internal';
|
|
11
11
|
import { VERSION, VAL_APP_PATH, VAL_OVERLAY_ID, VAL_APP_ID } from '@valbuild/ui';
|
|
12
12
|
import { useRouter, useRouterState } from '@tanstack/react-router';
|
|
13
|
-
import React, { useEffect,
|
|
13
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
14
14
|
import { V as ValOverlayProvider } from './ValOverlayContext-bd2f453c.esm.js';
|
|
15
|
-
import { VAL_CONFIG_SESSION_STORAGE_KEY, VAL_THEME_SESSION_STORAGE_KEY, markEmptyTextFields, VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, EMPTY_TEXT_RULES, installPageLog, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, BRIDGE_CAPABILITIES, isValCanvasStudioMessage, restoreScroll, interactWithPage, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, replayKeys, isCodeChangedDetail, holdKeys, startInlineEditing, screenshotPage, readPageSnapshot, installPageLogInCanvasFrame, isValCanvasFrame } from '@valbuild/shared/client';
|
|
15
|
+
import { VAL_CONFIG_SESSION_STORAGE_KEY, VAL_THEME_SESSION_STORAGE_KEY, VAL_CANVAS_EDITING_ATTRIBUTE, markEmptyTextFields, VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, VAL_CANVAS_SELECTION_PROPERTY, VAL_COMPONENT_DRAGGING_ATTRIBUTE, VAL_COMPONENT_ATTRIBUTE, EMPTY_TEXT_RULES, installPageLog, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, BRIDGE_CAPABILITIES, isValCanvasStudioMessage, restoreScroll, interactWithPage, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, replayKeys, isCodeChangedDetail, isOnValCanvasControls, holdKeys, startInlineEditing, screenshotPage, readPageSnapshot, installPageLogInCanvasFrame, isValCanvasFrame } from '@valbuild/shared/client';
|
|
16
16
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
17
17
|
import { D as DEMO_CLAIM_MESSAGE, a as DEMO_SERVICE_WORKER_PATH, b as DEMO_RELAY_MESSAGE } from './demoServiceWorker-56fd96cf.esm.js';
|
|
18
18
|
|
|
@@ -290,6 +290,15 @@ function ValCanvasBridge(_ref) {
|
|
|
290
290
|
// installed once and would otherwise close over the first value forever.
|
|
291
291
|
var pickingRef = React.useRef(false);
|
|
292
292
|
pickingRef.current = picking;
|
|
293
|
+
// Said on the document too, for the controls `ValComponentEditor` draws:
|
|
294
|
+
// they are shown only while Select is on.
|
|
295
|
+
React.useEffect(function () {
|
|
296
|
+
var root = document.documentElement;
|
|
297
|
+
root.toggleAttribute(VAL_CANVAS_EDITING_ATTRIBUTE, picking);
|
|
298
|
+
return function () {
|
|
299
|
+
return root.removeAttribute(VAL_CANVAS_EDITING_ATTRIBUTE);
|
|
300
|
+
};
|
|
301
|
+
}, [picking]);
|
|
293
302
|
/**
|
|
294
303
|
* Picking ANY element (`pickElements`), as the studio last said. `null`
|
|
295
304
|
* until it says.
|
|
@@ -950,6 +959,9 @@ function ValCanvasBridge(_ref) {
|
|
|
950
959
|
var _heldKeys$current2;
|
|
951
960
|
var target = event.target;
|
|
952
961
|
if (!(target instanceof Element)) return;
|
|
962
|
+
// Val's own controls on a list of components, not the page's content:
|
|
963
|
+
// the click is theirs, wherever in the page they are drawn.
|
|
964
|
+
if (isOnValCanvasControls(target)) return;
|
|
953
965
|
// A click in the field being typed in places the caret, and that is
|
|
954
966
|
// all it does: it is neither a pick nor a click on the link or button
|
|
955
967
|
// the text happens to be in. (The caret is the mousedown's, so
|
|
@@ -1256,7 +1268,14 @@ function ValCanvasBridge(_ref) {
|
|
|
1256
1268
|
// CSS string. A path contains quotes (`?p="/"`) and would otherwise
|
|
1257
1269
|
// close the selector early.
|
|
1258
1270
|
dangerouslySetInnerHTML: {
|
|
1259
|
-
__html: [
|
|
1271
|
+
__html: [":root { ".concat(VAL_CANVAS_SELECTION_PROPERTY, ": ").concat(selectionColors.selection, "; }"),
|
|
1272
|
+
// Not around a component's item: its controls outline it, and two
|
|
1273
|
+
// boxes on one element is one too many. The conditions are in
|
|
1274
|
+
// `:where()`, which counts for nothing: this rule must stay as
|
|
1275
|
+
// weak as `[data-val-path]` alone, or it beats the outline of the
|
|
1276
|
+
// field the Studio is on (`highlightRule`, below) and that field
|
|
1277
|
+
// looks like every other one while Select is on.
|
|
1278
|
+
picking ? ":where(:root:not([".concat(VAL_COMPONENT_DRAGGING_ATTRIBUTE, "])) [data-val-path]:where(:not([").concat(VAL_COMPONENT_ATTRIBUTE, "])) { outline: 1px solid ").concat(selectionColors.selectionSoft, "; outline-offset: 1px; cursor: pointer; }\n:where(:root:not([").concat(VAL_COMPONENT_DRAGGING_ATTRIBUTE, "])) [data-val-path]:where(:not([").concat(VAL_COMPONENT_ATTRIBUTE, "])):hover { outline: 2px solid ").concat(selectionColors.selection, "; }") : "",
|
|
1260
1279
|
// The one rule here that moves the page, and only while Select is
|
|
1261
1280
|
// on: an emptied text's line of room, without which it cannot be
|
|
1262
1281
|
// pointed at. See `emptyTextFields.ts` for why, and how narrowly.
|
|
@@ -2703,6 +2722,143 @@ function readParentPathname() {
|
|
|
2703
2722
|
|
|
2704
2723
|
var ValProvider = ValTanStackProvider;
|
|
2705
2724
|
|
|
2725
|
+
/**
|
|
2726
|
+
* EXPERIMENTAL: the preview route's side of its conversation with the Studio.
|
|
2727
|
+
* Wrap `Unstable_ValComponentPreview` in it.
|
|
2728
|
+
*
|
|
2729
|
+
* It keeps the frame as tall as the component, sends a click on content to
|
|
2730
|
+
* the Studio so it can open that field, and reads the content again when an
|
|
2731
|
+
* edit is made - `router.invalidate()`, which re-runs the route's loader. See
|
|
2732
|
+
* `ValPreviewBridgeCore` in `@valbuild/react/internal` for the details.
|
|
2733
|
+
*
|
|
2734
|
+
* It also switches on the edit tags. Everywhere else `ValProvider` does that,
|
|
2735
|
+
* once hydration has told it the Studio is open; the preview route is not
|
|
2736
|
+
* under the site's `ValProvider`, and is rendered in the browser only
|
|
2737
|
+
* (`ssr: false`), so it can tag from its first render.
|
|
2738
|
+
*
|
|
2739
|
+
* @example
|
|
2740
|
+
* // src/routes/val-preview.tsx
|
|
2741
|
+
* <ValPreviewBridge>
|
|
2742
|
+
* <Unstable_ValComponentPreview
|
|
2743
|
+
* valModules={valModules}
|
|
2744
|
+
* source={Route.useLoaderData()}
|
|
2745
|
+
* />
|
|
2746
|
+
* </ValPreviewBridge>
|
|
2747
|
+
*/
|
|
2748
|
+
function ValPreviewBridge(_ref) {
|
|
2749
|
+
var children = _ref.children;
|
|
2750
|
+
var router = useRouter();
|
|
2751
|
+
// Before the children render, so their JSX is created with the tags on.
|
|
2752
|
+
// A global switch, and idempotent: setting it again on a re-render is free.
|
|
2753
|
+
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
2754
|
+
return /*#__PURE__*/jsx(ValPreviewBridgeCore, {
|
|
2755
|
+
onRefresh: function onRefresh() {
|
|
2756
|
+
return router.invalidate();
|
|
2757
|
+
},
|
|
2758
|
+
children: children
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
/**
|
|
2763
|
+
* EXPERIMENTAL: renders the value at a source path with the component its
|
|
2764
|
+
* schema declares - `s.object(...).component(() => import(...))`.
|
|
2765
|
+
*
|
|
2766
|
+
* The TanStack half of a component preview. The content is read on the server
|
|
2767
|
+
* (`unstable_fetchValPreviewSource` from `@valbuild/tanstack/server`, through
|
|
2768
|
+
* a server function in the route's loader), and the component is found and
|
|
2769
|
+
* rendered here, in the browser: its `import()` is the app's own, so it is
|
|
2770
|
+
* the app's code that renders it, with the app's CSS.
|
|
2771
|
+
*
|
|
2772
|
+
* `source` is what the loader returned; the rest says what to render.
|
|
2773
|
+
*
|
|
2774
|
+
* `Unstable_` rather than `unstable_` like `@valbuild/next`'s
|
|
2775
|
+
* `unstable_renderValComponent`: this one is a component, and JSX reads a tag
|
|
2776
|
+
* that starts with a lower-case letter as an HTML element.
|
|
2777
|
+
*/
|
|
2778
|
+
function Unstable_ValComponentPreview(_ref) {
|
|
2779
|
+
var valModules = _ref.valModules,
|
|
2780
|
+
source = _ref.source,
|
|
2781
|
+
example = _ref.example,
|
|
2782
|
+
props = _ref.props;
|
|
2783
|
+
var _useState = useState(null),
|
|
2784
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
2785
|
+
resolution = _useState2[0],
|
|
2786
|
+
setResolution = _useState2[1];
|
|
2787
|
+
useEffect(function () {
|
|
2788
|
+
if (source.status === "error") {
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
var cancelled = false;
|
|
2792
|
+
_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
2793
|
+
var valModule, next, _t;
|
|
2794
|
+
return _regenerator().w(function (_context) {
|
|
2795
|
+
while (1) switch (_context.n) {
|
|
2796
|
+
case 0:
|
|
2797
|
+
_context.n = 1;
|
|
2798
|
+
return findValModule(valModules, source.sourcePath);
|
|
2799
|
+
case 1:
|
|
2800
|
+
valModule = _context.v;
|
|
2801
|
+
if (!valModule) {
|
|
2802
|
+
_context.n = 3;
|
|
2803
|
+
break;
|
|
2804
|
+
}
|
|
2805
|
+
_context.n = 2;
|
|
2806
|
+
return resolveValComponentPreview({
|
|
2807
|
+
valModule: valModule,
|
|
2808
|
+
sourcePath: source.sourcePath,
|
|
2809
|
+
moduleValue: JSON.parse(source.moduleJson),
|
|
2810
|
+
example: example,
|
|
2811
|
+
props: props
|
|
2812
|
+
});
|
|
2813
|
+
case 2:
|
|
2814
|
+
_t = _context.v;
|
|
2815
|
+
_context.n = 4;
|
|
2816
|
+
break;
|
|
2817
|
+
case 3:
|
|
2818
|
+
_t = {
|
|
2819
|
+
status: "error",
|
|
2820
|
+
message: "No module for '".concat(source.sourcePath, "' in val.modules.")
|
|
2821
|
+
};
|
|
2822
|
+
case 4:
|
|
2823
|
+
next = _t;
|
|
2824
|
+
if (!cancelled) {
|
|
2825
|
+
setResolution(next);
|
|
2826
|
+
}
|
|
2827
|
+
case 5:
|
|
2828
|
+
return _context.a(2);
|
|
2829
|
+
}
|
|
2830
|
+
}, _callee);
|
|
2831
|
+
}))()["catch"](function (err) {
|
|
2832
|
+
if (!cancelled) {
|
|
2833
|
+
setResolution({
|
|
2834
|
+
status: "error",
|
|
2835
|
+
message: err instanceof Error ? err.message : String(err)
|
|
2836
|
+
});
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
return function () {
|
|
2840
|
+
cancelled = true;
|
|
2841
|
+
};
|
|
2842
|
+
}, [valModules, source, example, props]);
|
|
2843
|
+
if (source.status === "error") {
|
|
2844
|
+
return /*#__PURE__*/jsx(ValPreviewMessage, {
|
|
2845
|
+
children: source.message
|
|
2846
|
+
});
|
|
2847
|
+
}
|
|
2848
|
+
// Nothing until the first resolution, and the previous one while the next
|
|
2849
|
+
// is on its way, so a refresh does not flash an empty frame.
|
|
2850
|
+
if (resolution === null) {
|
|
2851
|
+
return null;
|
|
2852
|
+
}
|
|
2853
|
+
if (resolution.status === "error") {
|
|
2854
|
+
return /*#__PURE__*/jsx(ValPreviewMessage, {
|
|
2855
|
+
children: resolution.message
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
var Component = resolution.Component;
|
|
2859
|
+
return /*#__PURE__*/jsx(Component, _objectSpread2({}, resolution.props));
|
|
2860
|
+
}
|
|
2861
|
+
|
|
2706
2862
|
function _objectWithoutPropertiesLoose(r, e) {
|
|
2707
2863
|
if (null == r) return {};
|
|
2708
2864
|
var t = {};
|
|
@@ -3526,4 +3682,4 @@ var Internal = _objectSpread2(_objectSpread2({}, Internal$1), {}, {
|
|
|
3526
3682
|
selfCheck: selfCheck
|
|
3527
3683
|
});
|
|
3528
3684
|
|
|
3529
|
-
export { Internal, ValApp, ValImage, ValModulesClient, ValProvider, ValVideo, initVal, useRegisterValModules };
|
|
3685
|
+
export { Internal, Unstable_ValComponentPreview, ValApp, ValImage, ValModulesClient, ValPreviewBridge, ValProvider, ValVideo, initVal, useRegisterValModules };
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"tanstack-router",
|
|
15
15
|
"react"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.154.
|
|
17
|
+
"version": "0.154.2",
|
|
18
18
|
"main": "dist/valbuild-tanstack.cjs.js",
|
|
19
19
|
"module": "dist/valbuild-tanstack.esm.js",
|
|
20
20
|
"exports": {
|
|
@@ -52,13 +52,13 @@
|
|
|
52
52
|
"exports": true
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@valbuild/core": "0.
|
|
56
|
-
"@valbuild/language-server": "0.154.
|
|
57
|
-
"@valbuild/mcp": "0.154.
|
|
58
|
-
"@valbuild/react": "0.154.
|
|
59
|
-
"@valbuild/server": "0.154.
|
|
60
|
-
"@valbuild/shared": "0.154.
|
|
61
|
-
"@valbuild/ui": "0.154.
|
|
55
|
+
"@valbuild/core": "0.154.2",
|
|
56
|
+
"@valbuild/language-server": "0.154.2",
|
|
57
|
+
"@valbuild/mcp": "0.154.2",
|
|
58
|
+
"@valbuild/react": "0.154.2",
|
|
59
|
+
"@valbuild/server": "0.154.2",
|
|
60
|
+
"@valbuild/shared": "0.154.2",
|
|
61
|
+
"@valbuild/ui": "0.154.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@tanstack/react-router": "^1.170.41",
|