@valbuild/tanstack 0.150.23 → 0.151.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 +187 -0
- package/README.md +11 -11
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +100 -293
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +100 -293
- package/client/dist/valbuild-tanstack-client.esm.js +99 -292
- package/dist/ValOverlayContext-1e50a557.cjs.prod.js +47 -0
- package/dist/ValOverlayContext-6826b4d9.esm.js +40 -0
- package/dist/ValOverlayContext-b18c2f18.cjs.dev.js +47 -0
- package/dist/declarations/src/ValDraft.d.ts +6 -50
- package/dist/declarations/src/ValModulesClient.d.ts +1 -3
- package/dist/declarations/src/ValProvider.d.ts +1 -1
- package/dist/declarations/src/client/initValClient.d.ts +25 -3
- package/dist/declarations/src/server/initValContent.d.ts +55 -169
- package/dist/{routeFromVal-06590f50.esm.js → routeFromVal-124235a5.esm.js} +3 -153
- package/dist/{routeFromVal-3c3915e2.cjs.dev.js → routeFromVal-2e834397.cjs.prod.js} +1 -156
- package/dist/{routeFromVal-b31a9e00.cjs.prod.js → routeFromVal-3d4d7c30.cjs.dev.js} +1 -156
- package/dist/{typeof-66e2d869.esm.js → typeof-3e1a1d11.esm.js} +1 -1
- package/dist/{typeof-8998e126.cjs.prod.js → typeof-56656438.cjs.prod.js} +0 -2
- package/dist/{typeof-dd0246a1.cjs.dev.js → typeof-bd6ec82c.cjs.dev.js} +0 -2
- package/dist/valbuild-tanstack.cjs.dev.js +162 -282
- package/dist/valbuild-tanstack.cjs.prod.js +162 -282
- package/dist/valbuild-tanstack.esm.js +162 -281
- package/dist/{version-3d755ee7.esm.js → version-2b3824bf.esm.js} +2 -19
- package/dist/{version-278a8d18.cjs.dev.js → version-8e19c405.cjs.dev.js} +1 -19
- package/dist/{version-30535975.cjs.prod.js → version-d46bc4bb.cjs.prod.js} +1 -19
- package/package.json +8 -8
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +278 -1140
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +278 -1140
- package/server/dist/valbuild-tanstack-server.esm.js +279 -1141
- package/dist/ValOverlayContext-198b4bd1.cjs.dev.js +0 -301
- package/dist/ValOverlayContext-6411bbe3.esm.js +0 -293
- package/dist/ValOverlayContext-d9b22d1a.cjs.prod.js +0 -301
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { _ as _asyncToGenerator, a as _regenerator } from './asyncToGenerator-500f022f.esm.js';
|
|
2
|
-
import { _ as _objectSpread2, a as _slicedToArray, b as _createForOfIteratorHelper, c as _typeof } from './typeof-
|
|
2
|
+
import { _ as _objectSpread2, a as _slicedToArray, b as _createForOfIteratorHelper, c as _arrayLikeToArray, d as _unsupportedIterableToArray, e as _typeof } from './typeof-3e1a1d11.esm.js';
|
|
3
3
|
import { Internal as Internal$1, initVal as initVal$1, DEFAULT_CONTENT_HOST } from '@valbuild/core';
|
|
4
4
|
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,
|
|
8
|
+
import { r as readValEnableCookie, V as VERSION$1 } from './version-2b3824bf.esm.js';
|
|
9
|
+
import { isDraft, createDraftStore, draftHolds, draftHoldsVersions, startRefreshLoop, applyValEvent } from '@valbuild/react/internal';
|
|
9
10
|
export { ValRichText } from '@valbuild/react/internal';
|
|
10
11
|
import { VERSION, VAL_APP_PATH, VAL_OVERLAY_ID, VAL_APP_ID } from '@valbuild/ui';
|
|
11
12
|
import { useRouter, useRouterState } from '@tanstack/react-router';
|
|
12
13
|
import React, { useEffect, useRef, useState } from 'react';
|
|
13
|
-
import { V as
|
|
14
|
+
import { V as ValOverlayProvider } from './ValOverlayContext-6826b4d9.esm.js';
|
|
14
15
|
import { VAL_CONFIG_SESSION_STORAGE_KEY, VAL_THEME_SESSION_STORAGE_KEY, VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, isValCanvasStudioMessage, restoreScroll, isDesignTabOrigin, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, quickPreviewSiteOrigin, readPageSnapshot, screenshotPage, isValCanvasFrame } from '@valbuild/shared/client';
|
|
15
16
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
16
17
|
import { D as DEMO_CLAIM_MESSAGE, a as DEMO_SERVICE_WORKER_PATH, b as DEMO_RELAY_MESSAGE } from './demoServiceWorker-56fd96cf.esm.js';
|
|
17
|
-
import '@valbuild/core/patch';
|
|
18
18
|
|
|
19
19
|
function getUnpatchedUnencodedVal(selector) {
|
|
20
20
|
// It is weird to use stega encode here since we never actually should stega encode,
|
|
@@ -210,6 +210,22 @@ var floatDarkBg = "#131316";
|
|
|
210
210
|
/** `--bg-float`, light. */
|
|
211
211
|
var floatLightBg = "#fcfcfc";
|
|
212
212
|
|
|
213
|
+
function _arrayWithoutHoles(r) {
|
|
214
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function _iterableToArray(r) {
|
|
218
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function _nonIterableSpread() {
|
|
222
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function _toConsumableArray(r) {
|
|
226
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
227
|
+
}
|
|
228
|
+
|
|
213
229
|
var DEFAULT_SELECTION = {
|
|
214
230
|
selection: DEFAULT_CANVAS_SELECTION,
|
|
215
231
|
selectionSoft: DEFAULT_CANVAS_SELECTION_SOFT
|
|
@@ -238,7 +254,9 @@ var RESCAN_INTERVAL_MS = 5000;
|
|
|
238
254
|
function ValCanvasBridge(_ref) {
|
|
239
255
|
var _elementPicking$modif;
|
|
240
256
|
var draftMode = _ref.draftMode,
|
|
241
|
-
isRefreshing = _ref.isRefreshing
|
|
257
|
+
isRefreshing = _ref.isRefreshing,
|
|
258
|
+
holds = _ref.holds,
|
|
259
|
+
holdsVersions = _ref.holdsVersions;
|
|
242
260
|
var _React$useState = React.useState(false),
|
|
243
261
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
244
262
|
picking = _React$useState2[0],
|
|
@@ -381,13 +399,17 @@ function ValCanvasBridge(_ref) {
|
|
|
381
399
|
|
|
382
400
|
// Announce the frame, and say whether it is actually showing draft content.
|
|
383
401
|
React.useEffect(function () {
|
|
384
|
-
post({
|
|
402
|
+
post(_objectSpread2(_objectSpread2({
|
|
385
403
|
val: VAL_CANVAS_MESSAGE,
|
|
386
404
|
type: "ready",
|
|
387
405
|
draftMode: draftMode,
|
|
388
406
|
url: window.location.href
|
|
389
|
-
}
|
|
390
|
-
|
|
407
|
+
}, holds !== undefined && holds.length > 0 ? {
|
|
408
|
+
holds: _toConsumableArray(holds)
|
|
409
|
+
} : {}), holdsVersions !== undefined && Object.keys(holdsVersions).length > 0 ? {
|
|
410
|
+
holdsVersions: holdsVersions
|
|
411
|
+
} : {}));
|
|
412
|
+
}, [post, draftMode, holds, holdsVersions]);
|
|
391
413
|
|
|
392
414
|
/**
|
|
393
415
|
* Re-scan whenever the page could have moved.
|
|
@@ -635,16 +657,17 @@ function ValCanvasBridge(_ref) {
|
|
|
635
657
|
* `ValTanStackProvider` listens for this event on its own window to make an
|
|
636
658
|
* inline edit visible behind the overlay; the only thing different here
|
|
637
659
|
* is that the edit was made in another window. Re-dispatching rather
|
|
638
|
-
* than reaching into the store keeps one path into the page
|
|
639
|
-
* the
|
|
640
|
-
* server component's own re-read across.
|
|
660
|
+
* than reaching into the store keeps one path into the page. (What
|
|
661
|
+
* re-reads the server's own content is `confirmed`, below.)
|
|
641
662
|
*/
|
|
642
663
|
window.dispatchEvent(new CustomEvent("val-event", {
|
|
643
|
-
detail: {
|
|
664
|
+
detail: _objectSpread2({
|
|
644
665
|
type: "source-update",
|
|
645
666
|
moduleFilePath: message.moduleFilePath,
|
|
646
667
|
source: message.source
|
|
647
|
-
}
|
|
668
|
+
}, message.read !== undefined ? {
|
|
669
|
+
read: message.read
|
|
670
|
+
} : {})
|
|
648
671
|
}));
|
|
649
672
|
return;
|
|
650
673
|
}
|
|
@@ -658,6 +681,17 @@ function ValCanvasBridge(_ref) {
|
|
|
658
681
|
}));
|
|
659
682
|
return;
|
|
660
683
|
}
|
|
684
|
+
if (message.type === "confirmed") {
|
|
685
|
+
// How far the server holds the editor's changes: what the provider
|
|
686
|
+
// re-reads its server-rendered content on. Relayed like the two above.
|
|
687
|
+
window.dispatchEvent(new CustomEvent("val-event", {
|
|
688
|
+
detail: {
|
|
689
|
+
type: "confirmed",
|
|
690
|
+
seq: message.seq
|
|
691
|
+
}
|
|
692
|
+
}));
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
661
695
|
setHighlighted(message.path);
|
|
662
696
|
if (message.path !== null && message.scrollIntoView) {
|
|
663
697
|
var target = findByPath(message.path);
|
|
@@ -1085,52 +1119,10 @@ function readPageReply(message) {
|
|
|
1085
1119
|
}
|
|
1086
1120
|
|
|
1087
1121
|
/**
|
|
1088
|
-
*
|
|
1089
|
-
*
|
|
1090
|
-
*
|
|
1091
|
-
*
|
|
1092
|
-
* a `router.invalidate()` fired on the edit can reach a server that has not saved
|
|
1093
|
-
* the patch yet: the payload comes back with the old content, and nothing
|
|
1094
|
-
* schedules another look. What an editor sees is a canvas that flickered and did
|
|
1095
|
-
* not change — which is indistinguishable from an edit that did not work.
|
|
1096
|
-
*
|
|
1097
|
-
* So the page asks again a little later. This is the "should I bother" half of
|
|
1098
|
-
* that, kept out of the effect and pure so the reasons NOT to are checkable:
|
|
1099
|
-
* every one of them is a whole-route request avoided, and in development Next
|
|
1100
|
-
* re-renders (and sometimes recompiles) the page for each one.
|
|
1101
|
-
*/
|
|
1102
|
-
function shouldSafetyRefresh(state) {
|
|
1103
|
-
// Never edited: a preview someone is only looking at has nothing to catch up
|
|
1104
|
-
// on, and polling it would cost a route render per tick for nothing.
|
|
1105
|
-
if (state.lastEditAt === 0) return false;
|
|
1106
|
-
// The editing stopped long enough ago that anything in flight has landed.
|
|
1107
|
-
if (state.now - state.lastEditAt > state.windowMs) return false;
|
|
1108
|
-
// Nobody is looking. The caller refreshes once on the way back instead.
|
|
1109
|
-
if (state.hidden) return false;
|
|
1110
|
-
// Already on its way. Stacking whole-route requests makes the slowness this
|
|
1111
|
-
// exists to paper over worse, not better.
|
|
1112
|
-
if (state.isRefreshing) return false;
|
|
1113
|
-
// One just went out — usually the edit-driven refresh, a moment ago.
|
|
1114
|
-
if (state.now - state.lastRefreshAt < state.minIntervalMs) return false;
|
|
1115
|
-
return true;
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
/**
|
|
1119
|
-
* What a draft page shows, read by the server for the request that renders it.
|
|
1120
|
-
*
|
|
1121
|
-
* The source of every module the editor's draft CHANGES -- the ones with
|
|
1122
|
-
* patches applied, published-not-yet-built ones included -- and nothing
|
|
1123
|
-
* else: a module without changes is the build's own source, which the page
|
|
1124
|
-
* already has. Handed to `<ValProvider draft>` so the server's render and the
|
|
1125
|
-
* browser's first render resolve the same text, and the page never shows the
|
|
1126
|
-
* published version first and the draft a moment later.
|
|
1127
|
-
*
|
|
1128
|
-
* A `.jsonValues()` module is in the shape the Studio's own store gives it: the
|
|
1129
|
-
* entries the draft edits hold their content, and every other entry is the
|
|
1130
|
-
* thunkless marker the hooks resolve from the bundle.
|
|
1131
|
-
*
|
|
1132
|
-
* Plain JSON, because it travels from a server function to the browser in the
|
|
1133
|
-
* page's loader data. `fetchValDraft` in `@valbuild/tanstack/server` reads it.
|
|
1122
|
+
* What a draft page shows, read by the server for the request that renders
|
|
1123
|
+
* it: see `ValDraft` in `@valbuild/react` (its `read`), where it moved when
|
|
1124
|
+
* `@valbuild/next`'s `ValProvider` took a `draft` too. Exported from here as
|
|
1125
|
+
* it always was.
|
|
1134
1126
|
*/
|
|
1135
1127
|
|
|
1136
1128
|
/**
|
|
@@ -1282,51 +1274,6 @@ function PlatformAnalytics(_ref) {
|
|
|
1282
1274
|
});
|
|
1283
1275
|
}
|
|
1284
1276
|
|
|
1285
|
-
var REFRESH_INTERVAL_MS = 500;
|
|
1286
|
-
|
|
1287
|
-
/**
|
|
1288
|
-
* How often the page re-reads the server on its own, without being told to.
|
|
1289
|
-
*
|
|
1290
|
-
* A safety net for a race no amount of care on this side can close. An edit is
|
|
1291
|
-
* applied to the client store immediately and saved to the server
|
|
1292
|
-
* asynchronously, so `router.invalidate()` fired on the edit can reach a server
|
|
1293
|
-
* that has not written the patch yet: the loaders come back with the old
|
|
1294
|
-
* content, the counter has already been cleared, and nothing schedules another
|
|
1295
|
-
* look. What you see is a canvas that flickered and did not change — which is
|
|
1296
|
-
* indistinguishable from an edit that did not work.
|
|
1297
|
-
*
|
|
1298
|
-
* The honest fix would be for the page to know when its patch has been
|
|
1299
|
-
* persisted, and it has no way to ask. So it asks again a little later instead.
|
|
1300
|
-
*/
|
|
1301
|
-
var SAFETY_REFRESH_MS = 10000;
|
|
1302
|
-
|
|
1303
|
-
/**
|
|
1304
|
-
* How long after an edit the safety net keeps looking.
|
|
1305
|
-
*
|
|
1306
|
-
* The reason to stop is that this re-runs every loader on the page: in
|
|
1307
|
-
* development that is a server round trip and a recompile, and a preview
|
|
1308
|
-
* nobody is editing has nothing to catch up on. So the net is armed by editing
|
|
1309
|
-
* and disarms itself when the editing stops — long enough after the last
|
|
1310
|
-
* keystroke that any write still in flight has certainly landed.
|
|
1311
|
-
*/
|
|
1312
|
-
var SAFETY_REFRESH_WINDOW_MS = 30000;
|
|
1313
|
-
|
|
1314
|
-
/**
|
|
1315
|
-
* Fired on this window when an edit has been applied to the client store.
|
|
1316
|
-
*
|
|
1317
|
-
* The refresh loop listens for it so it can start the round trip immediately
|
|
1318
|
-
* rather than on its next tick. A DOM event rather than state, because the
|
|
1319
|
-
* counter it accompanies is a ref and the loop lives in an effect that must not
|
|
1320
|
-
* be torn down and rebuilt per keystroke.
|
|
1321
|
-
*/
|
|
1322
|
-
var VAL_EDIT_LANDED = "val-edit-landed";
|
|
1323
|
-
|
|
1324
|
-
/**
|
|
1325
|
-
* How often `/draft/stat` is asked when nothing is in progress.
|
|
1326
|
-
*
|
|
1327
|
-
* Draft mode changes when someone toggles it, which the handshake below already
|
|
1328
|
-
* covers — so this is only there to notice it being changed somewhere else.
|
|
1329
|
-
*/
|
|
1330
1277
|
var DRAFT_IDLE_POLL_MS = 20000;
|
|
1331
1278
|
|
|
1332
1279
|
/**
|
|
@@ -1407,7 +1354,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1407
1354
|
* draft mode is on, and one that is ONLY a snapshot (`draftMode: false`) is
|
|
1408
1355
|
* not a draft: it must not turn draft mode on or say the draft is synced.
|
|
1409
1356
|
*/
|
|
1410
|
-
var hasDraft = initialDraft
|
|
1357
|
+
var hasDraft = isDraft(initialDraft);
|
|
1411
1358
|
/*
|
|
1412
1359
|
* As the page was rendered. A ref, not the prop, for the reason
|
|
1413
1360
|
* `initialDraft` is one: a later render's prop is a client navigation's
|
|
@@ -1435,29 +1382,24 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1435
1382
|
var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
|
|
1436
1383
|
var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
|
|
1437
1384
|
var liveSitePage = isLiveSitePage(initialDraft);
|
|
1438
|
-
/*
|
|
1439
|
-
* The base the Studio's overlay must start from, where it is not the
|
|
1440
|
-
* bundle's (`ValDraft.base`): set while rendering, not in an effect, so it
|
|
1441
|
-
* is in place before the overlay -- loaded after this page hydrates -- takes
|
|
1442
|
-
* its modules in. The same value every render, from a ref, so writing it
|
|
1443
|
-
* again is harmless.
|
|
1444
|
-
*/
|
|
1445
|
-
if (typeof window !== "undefined") {
|
|
1446
|
-
window.__VAL_BASE__ = hasDraft ? initialDraft.base : undefined;
|
|
1447
|
-
}
|
|
1448
1385
|
// TODO: move below into react package
|
|
1449
1386
|
var valStore = React.useMemo(function () {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
return
|
|
1460
|
-
}, [initialDraft
|
|
1387
|
+
return createDraftStore(initialDraft);
|
|
1388
|
+
}, [initialDraft]);
|
|
1389
|
+
/**
|
|
1390
|
+
* What this page reports to the Studio when it connects: the modules it
|
|
1391
|
+
* was rendered with a draft of (`draftHolds`). The Studio sends each of
|
|
1392
|
+
* them in its catch-up, so a draft that stopped being the draft before the
|
|
1393
|
+
* Studio was there -- discarded, published -- does not stay on the page.
|
|
1394
|
+
*/
|
|
1395
|
+
var holds = React.useMemo(function () {
|
|
1396
|
+
return draftHolds(initialDraft);
|
|
1397
|
+
}, [initialDraft]);
|
|
1398
|
+
// And the version of each, where the draft says: one the Studio would send
|
|
1399
|
+
// at the same version is the same content, and is not sent again.
|
|
1400
|
+
var holdsVersions = React.useMemo(function () {
|
|
1401
|
+
return draftHoldsVersions(initialDraft);
|
|
1402
|
+
}, [initialDraft]);
|
|
1461
1403
|
// Whether useValStega should actually suspend. False during SSR and the
|
|
1462
1404
|
// hydration render. Two paths: without `draft` the server store is empty
|
|
1463
1405
|
// (draft data arrives via browser CustomEvents only), so suspending there
|
|
@@ -1513,7 +1455,25 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1513
1455
|
var _React$useState11 = React.useState(hasDraft ? true : null),
|
|
1514
1456
|
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
|
1515
1457
|
draftMode = _React$useState12[0],
|
|
1516
|
-
|
|
1458
|
+
setDraftModeState = _React$useState12[1];
|
|
1459
|
+
/**
|
|
1460
|
+
* `draftMode` as last set: what an answer from `/draft/stat` is compared
|
|
1461
|
+
* with, to know whether it MOVED draft mode and so whether to refresh.
|
|
1462
|
+
*
|
|
1463
|
+
* Compared here, and the refresh sent after `setDraftMode`, rather than in
|
|
1464
|
+
* a `setDraftMode` updater: React may call an updater twice (StrictMode)
|
|
1465
|
+
* or during a render, and a refresh is a side effect -- run twice it is
|
|
1466
|
+
* two refreshes, and run in a render it is a `startTransition` while
|
|
1467
|
+
* rendering, which React refuses with a warning.
|
|
1468
|
+
*/
|
|
1469
|
+
var draftModeRef = React.useRef(draftMode);
|
|
1470
|
+
/** Set draft mode; `true` when that moved it. */
|
|
1471
|
+
var setDraftMode = function setDraftMode(next) {
|
|
1472
|
+
var moved = draftModeRef.current !== next;
|
|
1473
|
+
draftModeRef.current = next;
|
|
1474
|
+
setDraftModeState(next);
|
|
1475
|
+
return moved;
|
|
1476
|
+
};
|
|
1517
1477
|
/**
|
|
1518
1478
|
* Resolves when `draftMode` stops being unknown.
|
|
1519
1479
|
*
|
|
@@ -1558,15 +1518,11 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1558
1518
|
isRefreshing = _React$useTransition2[0],
|
|
1559
1519
|
startTransition = _React$useTransition2[1];
|
|
1560
1520
|
/**
|
|
1561
|
-
* The
|
|
1562
|
-
*
|
|
1563
|
-
*
|
|
1564
|
-
* owns the timers and the "when did we last edit" bookkeeping, and tearing
|
|
1565
|
-
* that down mid-flurry loses it. A ref updated on render is the value without
|
|
1566
|
-
* the dependency.
|
|
1521
|
+
* The page's refresh loop, while the overlay is up: the `val-event`
|
|
1522
|
+
* listener tells it what the Studio says. A ref, so the listener's effect
|
|
1523
|
+
* is not rebuilt with it.
|
|
1567
1524
|
*/
|
|
1568
|
-
var
|
|
1569
|
-
var rerenderCounterRef = React.useRef(0);
|
|
1525
|
+
var refreshLoopRef = React.useRef(null);
|
|
1570
1526
|
var _React$useState15 = React.useState(null),
|
|
1571
1527
|
_React$useState16 = _slicedToArray(_React$useState15, 2),
|
|
1572
1528
|
iframeSrc = _React$useState16[0],
|
|
@@ -1576,7 +1532,6 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1576
1532
|
return state.location.pathname;
|
|
1577
1533
|
}
|
|
1578
1534
|
});
|
|
1579
|
-
isRefreshingRef.current = isRefreshing;
|
|
1580
1535
|
useEffect(function () {
|
|
1581
1536
|
window.dispatchEvent(new CustomEvent("val-provider:pathname", {
|
|
1582
1537
|
detail: pathname
|
|
@@ -1684,7 +1639,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1684
1639
|
// suspends — no fallback flash — and the swap to draft data commits as a
|
|
1685
1640
|
// normal update instead of a hydration mismatch. Never deactivated:
|
|
1686
1641
|
// components must not stop suspending across renders (the draft-mode-off
|
|
1687
|
-
// release valve lives in
|
|
1642
|
+
// release valve lives in `overlaySource` instead).
|
|
1688
1643
|
/*
|
|
1689
1644
|
* Gated on `mountOverlay`, not on the cookie directly — the ORDER is the
|
|
1690
1645
|
* point.
|
|
@@ -1709,17 +1664,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1709
1664
|
}, [props.suspend, mountOverlay]);
|
|
1710
1665
|
|
|
1711
1666
|
/**
|
|
1712
|
-
* Re-
|
|
1713
|
-
*
|
|
1714
|
-
*
|
|
1715
|
-
*
|
|
1716
|
-
* round trip even began — pure dead time on top of a request that is already
|
|
1717
|
-
* the slow part in development. Refreshing on arrival and *then* enforcing the
|
|
1718
|
-
* gap keeps the same ceiling on requests while removing the wait.
|
|
1719
|
-
*
|
|
1720
|
-
* Still a counter rather than a boolean: edits that arrive during the gap have
|
|
1721
|
-
* to be picked up by the next refresh, and the count is what says whether
|
|
1722
|
-
* there are any.
|
|
1667
|
+
* Re-run the loaders when the server has the editor's changes: once per
|
|
1668
|
+
* version the Studio says it has confirmed (`startRefreshLoop`), never on
|
|
1669
|
+
* a timer and never when an edit merely arrives -- arrived, it raced the
|
|
1670
|
+
* write and came back without the edit.
|
|
1723
1671
|
*/
|
|
1724
1672
|
React.useEffect(function () {
|
|
1725
1673
|
// A demo's loaders read a server that never sees the tab's edits, so
|
|
@@ -1727,92 +1675,30 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1727
1675
|
if (!mountOverlay || props.disableRefresh || props.demo) {
|
|
1728
1676
|
return;
|
|
1729
1677
|
}
|
|
1730
|
-
var
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
*/
|
|
1749
|
-
void router.invalidate();
|
|
1750
|
-
});
|
|
1751
|
-
};
|
|
1752
|
-
var _tick = function tick() {
|
|
1753
|
-
timer = null;
|
|
1754
|
-
if (rerenderCounterRef.current === 0) return;
|
|
1755
|
-
var since = Date.now() - lastRefreshAt;
|
|
1756
|
-
if (since >= REFRESH_INTERVAL_MS) {
|
|
1757
|
-
refresh();
|
|
1758
|
-
} else {
|
|
1759
|
-
timer = setTimeout(_tick, REFRESH_INTERVAL_MS - since);
|
|
1760
|
-
}
|
|
1761
|
-
};
|
|
1762
|
-
var onEdit = function onEdit() {
|
|
1763
|
-
lastEditAt = Date.now();
|
|
1764
|
-
if (timer !== null) return;
|
|
1765
|
-
timer = setTimeout(_tick, 0);
|
|
1766
|
-
};
|
|
1767
|
-
window.addEventListener(VAL_EDIT_LANDED, onEdit);
|
|
1768
|
-
// A backstop for the counter being bumped without the event — the two are
|
|
1769
|
-
// incremented in the same places today, but the poll is what made this
|
|
1770
|
-
// correct regardless of who bumped it.
|
|
1771
|
-
var interval = setInterval(_tick, REFRESH_INTERVAL_MS);
|
|
1772
|
-
|
|
1773
|
-
/**
|
|
1774
|
-
* The safety net: look again, whether or not anything told us to.
|
|
1775
|
-
*
|
|
1776
|
-
* The reasons not to are in `shouldSafetyRefresh`, where they can be tested.
|
|
1777
|
-
* `hidden` is the one this side has to remember something about: a skipped
|
|
1778
|
-
* tick is worth one look when the tab comes back.
|
|
1779
|
-
*/
|
|
1780
|
-
var safetyTick = function safetyTick() {
|
|
1781
|
-
if (document.hidden) {
|
|
1782
|
-
missedWhileHidden = true;
|
|
1783
|
-
return;
|
|
1678
|
+
var loop = startRefreshLoop({
|
|
1679
|
+
refresh: function refresh() {
|
|
1680
|
+
var done;
|
|
1681
|
+
startTransition(function () {
|
|
1682
|
+
/*
|
|
1683
|
+
* Re-run the loaders of every match, then re-render.
|
|
1684
|
+
*
|
|
1685
|
+
* TanStack's equivalent of `router.refresh()`. `invalidate()` marks
|
|
1686
|
+
* the current matches stale and re-runs their loaders — which is
|
|
1687
|
+
* where a TanStack Start app reads Val content on the server — so
|
|
1688
|
+
* this is the round trip that brings an edit across. It resolves
|
|
1689
|
+
* when the loaders have settled, which is what keeps `isRefreshing`
|
|
1690
|
+
* honest, and what lets the loop hold a newer version until this
|
|
1691
|
+
* one is in.
|
|
1692
|
+
*/
|
|
1693
|
+
done = router.invalidate();
|
|
1694
|
+
});
|
|
1695
|
+
return done;
|
|
1784
1696
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
lastEditAt: lastEditAt,
|
|
1788
|
-
lastRefreshAt: lastRefreshAt,
|
|
1789
|
-
hidden: false,
|
|
1790
|
-
isRefreshing: isRefreshingRef.current,
|
|
1791
|
-
windowMs: SAFETY_REFRESH_WINDOW_MS,
|
|
1792
|
-
minIntervalMs: REFRESH_INTERVAL_MS
|
|
1793
|
-
});
|
|
1794
|
-
if (go) refresh();
|
|
1795
|
-
};
|
|
1796
|
-
var safety = setInterval(safetyTick, SAFETY_REFRESH_MS);
|
|
1797
|
-
/**
|
|
1798
|
-
* Coming back to the tab is worth one look.
|
|
1799
|
-
*
|
|
1800
|
-
* Otherwise a background tab skips its ticks and then has to wait out a
|
|
1801
|
-
* whole interval on return — which is exactly the moment someone is looking
|
|
1802
|
-
* at the page to see whether their edit took.
|
|
1803
|
-
*/
|
|
1804
|
-
var onVisibilityChange = function onVisibilityChange() {
|
|
1805
|
-
if (document.hidden || !missedWhileHidden) return;
|
|
1806
|
-
missedWhileHidden = false;
|
|
1807
|
-
safetyTick();
|
|
1808
|
-
};
|
|
1809
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
1697
|
+
});
|
|
1698
|
+
refreshLoopRef.current = loop;
|
|
1810
1699
|
return function () {
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
clearInterval(interval);
|
|
1814
|
-
clearInterval(safety);
|
|
1815
|
-
if (timer !== null) clearTimeout(timer);
|
|
1700
|
+
refreshLoopRef.current = null;
|
|
1701
|
+
loop.stop();
|
|
1816
1702
|
};
|
|
1817
1703
|
}, [mountOverlay, props.disableRefresh, props.demo]);
|
|
1818
1704
|
React.useEffect(function () {
|
|
@@ -1898,14 +1784,11 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1898
1784
|
Internal$1.log.error("could not get draft mode status", res);
|
|
1899
1785
|
return;
|
|
1900
1786
|
}
|
|
1901
|
-
setDraftMode(
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
}
|
|
1907
|
-
return prev;
|
|
1908
|
-
});
|
|
1787
|
+
if (setDraftMode(res.json.draftMode)) {
|
|
1788
|
+
var _refreshLoopRef$curre;
|
|
1789
|
+
// What the loaders read moved with it.
|
|
1790
|
+
(_refreshLoopRef$curre = refreshLoopRef.current) === null || _refreshLoopRef$curre === void 0 || _refreshLoopRef$curre.refresh();
|
|
1791
|
+
}
|
|
1909
1792
|
})["catch"](function (err) {
|
|
1910
1793
|
Internal$1.log.error("could not get draft mode status", err);
|
|
1911
1794
|
})["finally"](function () {
|
|
@@ -1951,10 +1834,12 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1951
1834
|
window.dispatchEvent(new CustomEvent("val-overlay-spa", {
|
|
1952
1835
|
detail: {
|
|
1953
1836
|
type: "draftMode",
|
|
1954
|
-
value: draftMode !== null && draftMode !== void 0 ? draftMode : false
|
|
1837
|
+
value: draftMode !== null && draftMode !== void 0 ? draftMode : false,
|
|
1838
|
+
holds: holds,
|
|
1839
|
+
holdsVersions: holdsVersions
|
|
1955
1840
|
}
|
|
1956
1841
|
}));
|
|
1957
|
-
}, [mountOverlay, draftMode, spaReady]);
|
|
1842
|
+
}, [mountOverlay, draftMode, spaReady, holds, holdsVersions]);
|
|
1958
1843
|
React.useEffect(function () {
|
|
1959
1844
|
if (!mountOverlay) {
|
|
1960
1845
|
// A visitor: only analytics tags content, and only after hydration
|
|
@@ -1971,45 +1856,39 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
1971
1856
|
// (`useEncodesEditTags`), so this cannot reach one still hydrating.
|
|
1972
1857
|
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
1973
1858
|
var reactServerComponentRefreshListener = function reactServerComponentRefreshListener(event) {
|
|
1974
|
-
if (event instanceof CustomEvent) {
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
window.dispatchEvent(new Event(VAL_EDIT_LANDED));
|
|
2004
|
-
}
|
|
2005
|
-
} else {
|
|
2006
|
-
Internal$1.log.error("invalid event detail", event.detail);
|
|
2007
|
-
}
|
|
1859
|
+
if (!(event instanceof CustomEvent)) {
|
|
1860
|
+
Internal$1.log.error("invalid custom event (val-event)", event);
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
var outcome = applyValEvent(valStore, event.detail);
|
|
1864
|
+
if (outcome.type === "synced") {
|
|
1865
|
+
setDraftSourcesSynced(true);
|
|
1866
|
+
return;
|
|
1867
|
+
}
|
|
1868
|
+
if (outcome.type === "confirmed") {
|
|
1869
|
+
var _refreshLoopRef$curre2;
|
|
1870
|
+
(_refreshLoopRef$curre2 = refreshLoopRef.current) === null || _refreshLoopRef$curre2 === void 0 || _refreshLoopRef$curre2.confirmed(outcome.seq);
|
|
1871
|
+
return;
|
|
1872
|
+
}
|
|
1873
|
+
if (outcome.type === "invalid") {
|
|
1874
|
+
Internal$1.log.error("invalid custom event details (val-event)", outcome.detail);
|
|
1875
|
+
return;
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* Not a refresh: the server may not have it yet. Only, before the
|
|
1879
|
+
* Studio's first `confirmed`, that this page's render is behind
|
|
1880
|
+
* what the Studio holds (`startRefreshLoop`). A module re-sent that
|
|
1881
|
+
* the page already shows does not count.
|
|
1882
|
+
*/
|
|
1883
|
+
if (outcome.changed) {
|
|
1884
|
+
if (outcome.fromPreviousStudio === true) {
|
|
1885
|
+
var _refreshLoopRef$curre3;
|
|
1886
|
+
// A Studio of the release before: it never confirms.
|
|
1887
|
+
(_refreshLoopRef$curre3 = refreshLoopRef.current) === null || _refreshLoopRef$curre3 === void 0 || _refreshLoopRef$curre3.changedByPreviousStudio();
|
|
2008
1888
|
} else {
|
|
2009
|
-
|
|
1889
|
+
var _refreshLoopRef$curre4;
|
|
1890
|
+
(_refreshLoopRef$curre4 = refreshLoopRef.current) === null || _refreshLoopRef$curre4 === void 0 || _refreshLoopRef$curre4.changed();
|
|
2010
1891
|
}
|
|
2011
|
-
} else {
|
|
2012
|
-
Internal$1.log.error("invalid custom event (val-event)", event);
|
|
2013
1892
|
}
|
|
2014
1893
|
};
|
|
2015
1894
|
window.addEventListener("val-event", reactServerComponentRefreshListener);
|
|
@@ -2018,7 +1897,7 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
2018
1897
|
};
|
|
2019
1898
|
}
|
|
2020
1899
|
}
|
|
2021
|
-
}, [mountOverlay, draftMode, analytics
|
|
1900
|
+
}, [mountOverlay, draftMode, analytics]);
|
|
2022
1901
|
React.useEffect(function () {
|
|
2023
1902
|
if (!mountOverlay) {
|
|
2024
1903
|
return;
|
|
@@ -2163,7 +2042,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
|
|
|
2163
2042
|
})]
|
|
2164
2043
|
}), mountOverlay && isCanvas && /*#__PURE__*/jsx(ValCanvasBridge, {
|
|
2165
2044
|
draftMode: draftMode === true,
|
|
2166
|
-
isRefreshing: isRefreshing
|
|
2045
|
+
isRefreshing: isRefreshing,
|
|
2046
|
+
holds: holds,
|
|
2047
|
+
holdsVersions: holdsVersions
|
|
2167
2048
|
}), mountOverlay && iframeSrc && /*#__PURE__*/jsx("iframe", {
|
|
2168
2049
|
loading: "eager",
|
|
2169
2050
|
style: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ as _asyncToGenerator, a as _regenerator } from './asyncToGenerator-500f022f.esm.js';
|
|
2
|
-
import { d as _arrayLikeToArray, e as _unsupportedIterableToArray } from './typeof-66e2d869.esm.js';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* How `initVal().isValEnabled()` reaches the server without importing it.
|
|
@@ -61,22 +60,6 @@ function _readValEnableCookie() {
|
|
|
61
60
|
return _readValEnableCookie.apply(this, arguments);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
function _arrayWithoutHoles(r) {
|
|
65
|
-
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function _iterableToArray(r) {
|
|
69
|
-
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function _nonIterableSpread() {
|
|
73
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function _toConsumableArray(r) {
|
|
77
|
-
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
63
|
var packageJson = {
|
|
81
64
|
name: "@valbuild/tanstack",
|
|
82
65
|
description: "Val for TanStack Start: hard-coded content - super-charged",
|
|
@@ -93,7 +76,7 @@ var packageJson = {
|
|
|
93
76
|
"tanstack-router",
|
|
94
77
|
"react"
|
|
95
78
|
],
|
|
96
|
-
version: "0.
|
|
79
|
+
version: "0.151.0",
|
|
97
80
|
scripts: {
|
|
98
81
|
typecheck: "tsc --noEmit",
|
|
99
82
|
test: "jest"
|
|
@@ -177,4 +160,4 @@ var packageJson = {
|
|
|
177
160
|
var _packageJson$version;
|
|
178
161
|
var VERSION = (_packageJson$version = packageJson.version) !== null && _packageJson$version !== void 0 ? _packageJson$version : null;
|
|
179
162
|
|
|
180
|
-
export { VERSION as V,
|
|
163
|
+
export { VERSION as V, readValEnableCookie as r, setValEnableCookieReader as s };
|