@valbuild/next 0.150.23 → 0.152.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 +175 -0
- package/README.md +82 -1
- package/client/dist/valbuild-next-client.cjs.dev.js +123 -256
- package/client/dist/valbuild-next-client.cjs.prod.js +123 -256
- package/client/dist/valbuild-next-client.esm.js +122 -255
- package/dist/{ValApp-a88a9ded.esm.js → ValApp-69cd599c.esm.js} +3 -3
- package/dist/{ValApp-c718d1a6.cjs.dev.js → ValApp-826dca6c.cjs.dev.js} +3 -3
- package/dist/ValApp-866089f6.cjs.js +7 -0
- package/dist/{ValApp-6c3da222.cjs.prod.js → ValApp-866089f6.cjs.prod.js} +3 -3
- package/dist/{ValCanvasBridge-9d221d32.cjs.dev.js → ValCanvasBridge-4b81f653.cjs.dev.js} +46 -13
- package/dist/ValCanvasBridge-6f568f1d.cjs.js +7 -0
- package/dist/{ValCanvasBridge-134c3ae1.cjs.prod.js → ValCanvasBridge-6f568f1d.cjs.prod.js} +46 -13
- package/dist/{ValCanvasBridge-4a5ef73c.esm.js → ValCanvasBridge-badc186b.esm.js} +46 -13
- package/dist/ValNextProvider-41d622a7.cjs.js +7 -0
- package/dist/{ValNextProvider-35d0b521.cjs.prod.js → ValNextProvider-41d622a7.cjs.prod.js} +124 -234
- package/dist/{ValNextProvider-a85a1d33.cjs.dev.js → ValNextProvider-4b9bcfc0.cjs.dev.js} +124 -234
- package/dist/{ValNextProvider-df6f351e.esm.js → ValNextProvider-745ed99e.esm.js} +124 -234
- package/dist/ValOverlayContext-0c29b6a7.cjs.dev.js +51 -0
- package/dist/ValOverlayContext-0f51d111.cjs.js +7 -0
- package/dist/ValOverlayContext-0f51d111.cjs.prod.js +51 -0
- package/dist/ValOverlayContext-178db68e.esm.js +37 -0
- package/dist/ValVideo-02f43a7c.cjs.js +7 -0
- package/dist/{ValVideo-dcd2b9f8.cjs.prod.js → ValVideo-02f43a7c.cjs.prod.js} +1 -2
- package/dist/{ValVideo-6e410ad8.cjs.dev.js → ValVideo-15e5c4fa.cjs.dev.js} +1 -2
- package/dist/{ValVideo-d377f06e.esm.js → ValVideo-8acf31b6.esm.js} +1 -2
- package/dist/{createForOfIteratorHelper-d4afcad8.cjs.prod.js → createForOfIteratorHelper-8459fbc7.cjs.prod.js} +1 -1
- package/dist/{createForOfIteratorHelper-5758a730.esm.js → createForOfIteratorHelper-9209e9dd.esm.js} +1 -1
- package/dist/{createForOfIteratorHelper-0445603c.cjs.dev.js → createForOfIteratorHelper-9c6aa3c7.cjs.dev.js} +1 -1
- package/dist/declarations/src/ValProvider.d.ts +1 -0
- package/dist/declarations/src/client/initValClient.d.ts +25 -3
- package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
- package/dist/declarations/src/rsc/index.d.ts +1 -0
- package/dist/declarations/src/rsc/initValRsc.d.ts +56 -118
- package/dist/{fallbackColors-149dfbc9.esm.js → fallbackColors-0d915c59.esm.js} +1 -1
- package/dist/{fallbackColors-080c1bbc.cjs.dev.js → fallbackColors-38f01ad2.cjs.dev.js} +1 -1
- package/dist/{fallbackColors-e1d73b36.cjs.prod.js → fallbackColors-d9a7b81e.cjs.prod.js} +1 -1
- package/dist/{objectSpread2-13f847a9.cjs.prod.js → objectSpread2-469273e9.cjs.prod.js} +25 -2
- package/dist/{objectSpread2-58024783.cjs.dev.js → objectSpread2-58726b14.cjs.dev.js} +25 -2
- package/dist/{objectSpread2-60d1bd93.esm.js → objectSpread2-f1f0d77a.esm.js} +24 -1
- package/dist/{routeFromVal-64cba2a6.esm.js → routeFromVal-80976677.esm.js} +5 -155
- package/dist/{routeFromVal-4df1157a.cjs.dev.js → routeFromVal-a1e0a8be.cjs.dev.js} +3 -159
- package/dist/{routeFromVal-812be6ea.cjs.prod.js → routeFromVal-c4dace91.cjs.prod.js} +3 -159
- package/dist/{slicedToArray-ce613de6.cjs.prod.js → slicedToArray-0fc63719.cjs.prod.js} +1 -1
- package/dist/{slicedToArray-aa291011.esm.js → slicedToArray-5ff32315.esm.js} +1 -1
- package/dist/{slicedToArray-44036a76.cjs.dev.js → slicedToArray-ed812733.cjs.dev.js} +1 -1
- package/dist/{unsupportedIterableToArray-c8ab77c9.cjs.dev.js → unsupportedIterableToArray-1aadf9fb.cjs.prod.js} +1 -0
- package/dist/{unsupportedIterableToArray-0d2087a2.cjs.prod.js → unsupportedIterableToArray-20a9209f.cjs.dev.js} +1 -0
- package/dist/{unsupportedIterableToArray-5baabfdc.esm.js → unsupportedIterableToArray-f57eb659.esm.js} +1 -1
- package/dist/useHydrated-8e90c7fa.cjs.js +7 -0
- package/dist/useHydrated-8e90c7fa.cjs.prod.js +34 -0
- package/dist/useHydrated-afcdbb66.esm.js +26 -0
- package/dist/useHydrated-ff733777.cjs.dev.js +34 -0
- package/dist/valbuild-next.cjs.dev.js +7 -8
- package/dist/valbuild-next.cjs.prod.js +7 -8
- package/dist/valbuild-next.esm.js +7 -8
- package/dist/{version-b292025f.cjs.dev.js → version-284ab1bc.cjs.prod.js} +1 -1
- package/dist/{version-8bac9fbe.esm.js → version-41472ee7.esm.js} +1 -1
- package/dist/{version-bfb6bbc0.cjs.prod.js → version-bab8ec07.cjs.dev.js} +1 -1
- package/package.json +8 -8
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +243 -872
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +243 -872
- package/rsc/dist/valbuild-next-rsc.esm.js +243 -872
- package/server/dist/valbuild-next-server.cjs.dev.js +4 -5
- package/server/dist/valbuild-next-server.cjs.prod.js +4 -5
- package/server/dist/valbuild-next-server.esm.js +4 -5
- package/dist/ValApp-6c3da222.cjs.js +0 -7
- package/dist/ValCanvasBridge-134c3ae1.cjs.js +0 -7
- package/dist/ValNextProvider-35d0b521.cjs.js +0 -7
- package/dist/ValOverlayContext-1a45e03d.esm.js +0 -290
- package/dist/ValOverlayContext-262899b3.cjs.dev.js +0 -301
- package/dist/ValOverlayContext-405ca70c.cjs.js +0 -7
- package/dist/ValOverlayContext-405ca70c.cjs.prod.js +0 -301
- package/dist/ValVideo-dcd2b9f8.cjs.js +0 -7
- package/dist/defineProperty-8951f469.cjs.prod.js +0 -29
- package/dist/defineProperty-cca5affa.esm.js +0 -26
- package/dist/defineProperty-f90345d7.cjs.dev.js +0 -29
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { _ as _slicedToArray } from './slicedToArray-
|
|
2
|
+
import { _ as _slicedToArray } from './slicedToArray-5ff32315.esm.js';
|
|
3
3
|
import { _ as _asyncToGenerator, a as _regenerator } from './asyncToGenerator-500f022f.esm.js';
|
|
4
|
-
import { _ as _objectSpread2 } from './objectSpread2-
|
|
4
|
+
import { _ as _objectSpread2 } from './objectSpread2-f1f0d77a.esm.js';
|
|
5
5
|
import { Internal, DEFAULT_CONTENT_HOST } from '@valbuild/core';
|
|
6
6
|
import { VERSION, VAL_APP_PATH, VAL_OVERLAY_ID } from '@valbuild/ui';
|
|
7
7
|
import { useRouter, usePathname } from 'next/navigation';
|
|
8
8
|
import Script from 'next/script';
|
|
9
9
|
import React, { useEffect } from 'react';
|
|
10
|
-
import {
|
|
10
|
+
import { ValOverlayProvider } from './ValOverlayContext-178db68e.esm.js';
|
|
11
11
|
import { SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
|
|
12
|
-
import {
|
|
12
|
+
import { isDraft, createDraftStore, draftHolds, draftHoldsVersions, startRefreshLoop, applyValEvent } from '@valbuild/react/internal';
|
|
13
|
+
import { p as prefixStyles, u as useConfigStorageSave, f as floatDarkBg, d as floatLightBg, v as valPrefixedClass, c as cn } from './fallbackColors-0d915c59.esm.js';
|
|
13
14
|
import { VAL_THEME_SESSION_STORAGE_KEY, isValCanvasFrame } from '@valbuild/shared/client';
|
|
14
|
-
import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-
|
|
15
|
-
import { ValCanvasBridge } from './ValCanvasBridge-
|
|
15
|
+
import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-9209e9dd.esm.js';
|
|
16
|
+
import { ValCanvasBridge } from './ValCanvasBridge-badc186b.esm.js';
|
|
16
17
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
17
|
-
import './unsupportedIterableToArray-
|
|
18
|
-
import './defineProperty-cca5affa.esm.js';
|
|
18
|
+
import './unsupportedIterableToArray-f57eb659.esm.js';
|
|
19
19
|
|
|
20
20
|
function initSessionTheme(config) {
|
|
21
21
|
if (typeof window === "undefined") {
|
|
@@ -69,82 +69,6 @@ function hasValEnableCookie(cookieString) {
|
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/**
|
|
73
|
-
* Whether the page should re-read the server on its own, right now.
|
|
74
|
-
*
|
|
75
|
-
* The page cannot know when its own edit has been persisted. An edit is applied
|
|
76
|
-
* to the client store immediately and written to the server asynchronously, so
|
|
77
|
-
* a `router.refresh()` fired on the edit can reach a server that has not saved
|
|
78
|
-
* the patch yet: the payload comes back with the old content, and nothing
|
|
79
|
-
* schedules another look. What an editor sees is a canvas that flickered and did
|
|
80
|
-
* not change — which is indistinguishable from an edit that did not work.
|
|
81
|
-
*
|
|
82
|
-
* So the page asks again a little later. This is the "should I bother" half of
|
|
83
|
-
* that, kept out of the effect and pure so the reasons NOT to are checkable:
|
|
84
|
-
* every one of them is a whole-route request avoided, and in development Next
|
|
85
|
-
* re-renders (and sometimes recompiles) the page for each one.
|
|
86
|
-
*/
|
|
87
|
-
function shouldSafetyRefresh(state) {
|
|
88
|
-
// Never edited: a preview someone is only looking at has nothing to catch up
|
|
89
|
-
// on, and polling it would cost a route render per tick for nothing.
|
|
90
|
-
if (state.lastEditAt === 0) return false;
|
|
91
|
-
// The editing stopped long enough ago that anything in flight has landed.
|
|
92
|
-
if (state.now - state.lastEditAt > state.windowMs) return false;
|
|
93
|
-
// Nobody is looking. The caller refreshes once on the way back instead.
|
|
94
|
-
if (state.hidden) return false;
|
|
95
|
-
// Already on its way. Stacking whole-route requests makes the slowness this
|
|
96
|
-
// exists to paper over worse, not better.
|
|
97
|
-
if (state.isRefreshing) return false;
|
|
98
|
-
// One just went out — usually the edit-driven refresh, a moment ago.
|
|
99
|
-
if (state.now - state.lastRefreshAt < state.minIntervalMs) return false;
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var REFRESH_INTERVAL_MS = 500;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* How often the page re-reads the server on its own, without being told to.
|
|
107
|
-
*
|
|
108
|
-
* A safety net for a race no amount of care on this side can close. An edit is
|
|
109
|
-
* applied to the client store immediately and saved to the server
|
|
110
|
-
* asynchronously, so `router.refresh()` fired on the edit can reach a server
|
|
111
|
-
* that has not written the patch yet: the RSC payload comes back with the old
|
|
112
|
-
* content, the counter has already been cleared, and nothing schedules another
|
|
113
|
-
* look. What you see is a canvas that flickered and did not change — which is
|
|
114
|
-
* indistinguishable from an edit that did not work.
|
|
115
|
-
*
|
|
116
|
-
* The honest fix would be for the page to know when its patch has been
|
|
117
|
-
* persisted, and it has no way to ask. So it asks again a little later instead.
|
|
118
|
-
*/
|
|
119
|
-
var SAFETY_REFRESH_MS = 10000;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* How long after an edit the safety net keeps looking.
|
|
123
|
-
*
|
|
124
|
-
* The reason to stop is that this is a whole-route request: in development Next
|
|
125
|
-
* re-renders (and sometimes recompiles) the page for every one, and a preview
|
|
126
|
-
* nobody is editing has nothing to catch up on. So the net is armed by editing
|
|
127
|
-
* and disarms itself when the editing stops — long enough after the last
|
|
128
|
-
* keystroke that any write still in flight has certainly landed.
|
|
129
|
-
*/
|
|
130
|
-
var SAFETY_REFRESH_WINDOW_MS = 30000;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Fired on this window when an edit has been applied to the client store.
|
|
134
|
-
*
|
|
135
|
-
* The refresh loop listens for it so it can start the round trip immediately
|
|
136
|
-
* rather than on its next tick. A DOM event rather than state, because the
|
|
137
|
-
* counter it accompanies is a ref and the loop lives in an effect that must not
|
|
138
|
-
* be torn down and rebuilt per keystroke.
|
|
139
|
-
*/
|
|
140
|
-
var VAL_EDIT_LANDED = "val-edit-landed";
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* How often `/draft/stat` is asked when nothing is in progress.
|
|
144
|
-
*
|
|
145
|
-
* Draft mode changes when someone toggles it, which the handshake below already
|
|
146
|
-
* covers — so this is only there to notice it being changed somewhere else.
|
|
147
|
-
*/
|
|
148
72
|
var DRAFT_IDLE_POLL_MS = 20000;
|
|
149
73
|
|
|
150
74
|
/**
|
|
@@ -171,7 +95,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
|
|
|
171
95
|
*/
|
|
172
96
|
var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
|
|
173
97
|
var ValNextProvider = function ValNextProvider(props) {
|
|
174
|
-
var _draftModeReady$curre2;
|
|
98
|
+
var _props$draft, _draftModeReady$curre2;
|
|
175
99
|
// TODO: use config:
|
|
176
100
|
var route = "/api/val";
|
|
177
101
|
/**
|
|
@@ -211,10 +135,32 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
211
135
|
}, _callee);
|
|
212
136
|
})), [route]);
|
|
213
137
|
|
|
138
|
+
/**
|
|
139
|
+
* The draft the page was rendered with, as it was at mount. A ref, not the
|
|
140
|
+
* prop: the server and the browser's first render must start from the
|
|
141
|
+
* same thing, and a later prop must not reset a store the overlay has been
|
|
142
|
+
* updating since. One that is not a draft (`draftMode: false`) is not one.
|
|
143
|
+
*/
|
|
144
|
+
var initialDraft = React.useRef((_props$draft = props.draft) !== null && _props$draft !== void 0 ? _props$draft : null).current;
|
|
145
|
+
var hasDraft = isDraft(initialDraft);
|
|
214
146
|
// TODO: move below into react package
|
|
215
147
|
var valStore = React.useMemo(function () {
|
|
216
|
-
return
|
|
217
|
-
}, []);
|
|
148
|
+
return createDraftStore(initialDraft);
|
|
149
|
+
}, [initialDraft]);
|
|
150
|
+
/**
|
|
151
|
+
* What this page reports to the Studio when it connects: the modules it
|
|
152
|
+
* was rendered with a draft of (`draftHolds`). The Studio sends each of
|
|
153
|
+
* them in its catch-up, so a draft that stopped being the draft before the
|
|
154
|
+
* Studio was there -- discarded, published -- does not stay on the page.
|
|
155
|
+
*/
|
|
156
|
+
var holds = React.useMemo(function () {
|
|
157
|
+
return draftHolds(initialDraft);
|
|
158
|
+
}, [initialDraft]);
|
|
159
|
+
// And the version of each, where the draft says: one the Studio would send
|
|
160
|
+
// at the same version is the same content, and is not sent again.
|
|
161
|
+
var holdsVersions = React.useMemo(function () {
|
|
162
|
+
return draftHoldsVersions(initialDraft);
|
|
163
|
+
}, [initialDraft]);
|
|
218
164
|
// Whether useValStega should actually suspend. False during SSR and the
|
|
219
165
|
// hydration render — the server store is never populated (draft data
|
|
220
166
|
// arrives via browser CustomEvents only), so suspending there would just
|
|
@@ -236,7 +182,9 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
236
182
|
* protocol. Without this the page could only wait out `waitForLoad`'s timeout,
|
|
237
183
|
* ten seconds per module nobody had edited.
|
|
238
184
|
*/
|
|
239
|
-
|
|
185
|
+
// A server-read draft is everything there is: a module missing from it has
|
|
186
|
+
// no changes, so there is nothing more to wait for.
|
|
187
|
+
var _React$useState3 = React.useState(hasDraft),
|
|
240
188
|
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
241
189
|
draftSourcesSynced = _React$useState4[0],
|
|
242
190
|
setDraftSourcesSynced = _React$useState4[1];
|
|
@@ -261,10 +209,30 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
261
209
|
_React$useState8 = _slicedToArray(_React$useState7, 2),
|
|
262
210
|
isCanvas = _React$useState8[0],
|
|
263
211
|
setIsCanvas = _React$useState8[1];
|
|
264
|
-
|
|
212
|
+
// Known on the server when it read a draft: a draft is only read in draft
|
|
213
|
+
// mode. Otherwise unknown until `/draft/stat` answers.
|
|
214
|
+
var _React$useState9 = React.useState(hasDraft ? true : null),
|
|
265
215
|
_React$useState0 = _slicedToArray(_React$useState9, 2),
|
|
266
216
|
draftMode = _React$useState0[0],
|
|
267
|
-
|
|
217
|
+
setDraftModeState = _React$useState0[1];
|
|
218
|
+
/**
|
|
219
|
+
* `draftMode` as last set: what an answer from `/draft/stat` is compared
|
|
220
|
+
* with, to know whether it MOVED draft mode and so whether to refresh.
|
|
221
|
+
*
|
|
222
|
+
* Compared here, and the refresh sent after `setDraftMode`, rather than in
|
|
223
|
+
* a `setDraftMode` updater: React may call an updater twice (StrictMode)
|
|
224
|
+
* or during a render, and a refresh is a side effect -- run twice it is
|
|
225
|
+
* two refreshes, and run in a render it is a `startTransition` while
|
|
226
|
+
* rendering, which React refuses with a warning.
|
|
227
|
+
*/
|
|
228
|
+
var draftModeRef = React.useRef(draftMode);
|
|
229
|
+
/** Set draft mode; `true` when that moved it. */
|
|
230
|
+
var setDraftMode = function setDraftMode(next) {
|
|
231
|
+
var moved = draftModeRef.current !== next;
|
|
232
|
+
draftModeRef.current = next;
|
|
233
|
+
setDraftModeState(next);
|
|
234
|
+
return moved;
|
|
235
|
+
};
|
|
268
236
|
/**
|
|
269
237
|
* Resolves when `draftMode` stops being unknown.
|
|
270
238
|
*
|
|
@@ -309,21 +277,16 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
309
277
|
isRefreshing = _React$useTransition2[0],
|
|
310
278
|
startTransition = _React$useTransition2[1];
|
|
311
279
|
/**
|
|
312
|
-
* The
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* owns the timers and the "when did we last edit" bookkeeping, and tearing
|
|
316
|
-
* that down mid-flurry loses it. A ref updated on render is the value without
|
|
317
|
-
* the dependency.
|
|
280
|
+
* The page's refresh loop, while the overlay is up: the `val-event`
|
|
281
|
+
* listener tells it what the Studio says. A ref, so the listener's effect
|
|
282
|
+
* is not rebuilt with it.
|
|
318
283
|
*/
|
|
319
|
-
var
|
|
320
|
-
var rerenderCounterRef = React.useRef(0);
|
|
284
|
+
var refreshLoopRef = React.useRef(null);
|
|
321
285
|
var _React$useState11 = React.useState(null),
|
|
322
286
|
_React$useState12 = _slicedToArray(_React$useState11, 2),
|
|
323
287
|
iframeSrc = _React$useState12[0],
|
|
324
288
|
setIframeSrc = _React$useState12[1];
|
|
325
289
|
var pathname = usePathname();
|
|
326
|
-
isRefreshingRef.current = isRefreshing;
|
|
327
290
|
useEffect(function () {
|
|
328
291
|
window.dispatchEvent(new CustomEvent("val-provider:pathname", {
|
|
329
292
|
detail: pathname
|
|
@@ -348,7 +311,7 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
348
311
|
// suspends — no fallback flash — and the swap to draft data commits as a
|
|
349
312
|
// normal update instead of a hydration mismatch. Never deactivated:
|
|
350
313
|
// components must not stop suspending across renders (the draft-mode-off
|
|
351
|
-
// release valve lives in
|
|
314
|
+
// release valve lives in `overlaySource` instead).
|
|
352
315
|
if (props.suspend && shouldEnableVal()) {
|
|
353
316
|
startTransition(function () {
|
|
354
317
|
setSuspendActive(true);
|
|
@@ -357,99 +320,30 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
357
320
|
}, [props.suspend]);
|
|
358
321
|
|
|
359
322
|
/**
|
|
360
|
-
* Re-render the server tree when
|
|
323
|
+
* Re-render the server tree when the server has the editor's changes: once
|
|
324
|
+
* per version the Studio says it has confirmed (`startRefreshLoop`), never
|
|
325
|
+
* on a timer and never when an edit merely arrives -- arrived, it raced
|
|
326
|
+
* the write, and the server components came back without the edit.
|
|
361
327
|
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
* the slow part in development. Refreshing on arrival and *then* enforcing the
|
|
366
|
-
* gap keeps the same ceiling on requests while removing the wait.
|
|
367
|
-
*
|
|
368
|
-
* Still a counter rather than a boolean: edits that arrive during the gap have
|
|
369
|
-
* to be picked up by the next refresh, and the count is what says whether
|
|
370
|
-
* there are any.
|
|
328
|
+
* `router.refresh()` does not say when it is done, so a version confirmed
|
|
329
|
+
* while one is on its way is a refresh of its own; the transition is what
|
|
330
|
+
* the canvas shows as busy (`isRefreshing`).
|
|
371
331
|
*/
|
|
372
332
|
React.useEffect(function () {
|
|
373
333
|
if (!mountOverlay || props.disableRefresh) {
|
|
374
334
|
return;
|
|
375
335
|
}
|
|
376
|
-
var
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
var missedWhileHidden = false;
|
|
382
|
-
var refresh = function refresh() {
|
|
383
|
-
rerenderCounterRef.current = 0;
|
|
384
|
-
lastRefreshAt = Date.now();
|
|
385
|
-
startTransition(function () {
|
|
386
|
-
router.refresh();
|
|
387
|
-
});
|
|
388
|
-
};
|
|
389
|
-
var _tick = function tick() {
|
|
390
|
-
timer = null;
|
|
391
|
-
if (rerenderCounterRef.current === 0) return;
|
|
392
|
-
var since = Date.now() - lastRefreshAt;
|
|
393
|
-
if (since >= REFRESH_INTERVAL_MS) {
|
|
394
|
-
refresh();
|
|
395
|
-
} else {
|
|
396
|
-
timer = setTimeout(_tick, REFRESH_INTERVAL_MS - since);
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
var onEdit = function onEdit() {
|
|
400
|
-
lastEditAt = Date.now();
|
|
401
|
-
if (timer !== null) return;
|
|
402
|
-
timer = setTimeout(_tick, 0);
|
|
403
|
-
};
|
|
404
|
-
window.addEventListener(VAL_EDIT_LANDED, onEdit);
|
|
405
|
-
// A backstop for the counter being bumped without the event — the two are
|
|
406
|
-
// incremented in the same places today, but the poll is what made this
|
|
407
|
-
// correct regardless of who bumped it.
|
|
408
|
-
var interval = setInterval(_tick, REFRESH_INTERVAL_MS);
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* The safety net: look again, whether or not anything told us to.
|
|
412
|
-
*
|
|
413
|
-
* The reasons not to are in `shouldSafetyRefresh`, where they can be tested.
|
|
414
|
-
* `hidden` is the one this side has to remember something about: a skipped
|
|
415
|
-
* tick is worth one look when the tab comes back.
|
|
416
|
-
*/
|
|
417
|
-
var safetyTick = function safetyTick() {
|
|
418
|
-
if (document.hidden) {
|
|
419
|
-
missedWhileHidden = true;
|
|
420
|
-
return;
|
|
336
|
+
var loop = startRefreshLoop({
|
|
337
|
+
refresh: function refresh() {
|
|
338
|
+
startTransition(function () {
|
|
339
|
+
router.refresh();
|
|
340
|
+
});
|
|
421
341
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
lastEditAt: lastEditAt,
|
|
425
|
-
lastRefreshAt: lastRefreshAt,
|
|
426
|
-
hidden: false,
|
|
427
|
-
isRefreshing: isRefreshingRef.current,
|
|
428
|
-
windowMs: SAFETY_REFRESH_WINDOW_MS,
|
|
429
|
-
minIntervalMs: REFRESH_INTERVAL_MS
|
|
430
|
-
});
|
|
431
|
-
if (go) refresh();
|
|
432
|
-
};
|
|
433
|
-
var safety = setInterval(safetyTick, SAFETY_REFRESH_MS);
|
|
434
|
-
/**
|
|
435
|
-
* Coming back to the tab is worth one look.
|
|
436
|
-
*
|
|
437
|
-
* Otherwise a background tab skips its ticks and then has to wait out a
|
|
438
|
-
* whole interval on return — which is exactly the moment someone is looking
|
|
439
|
-
* at the page to see whether their edit took.
|
|
440
|
-
*/
|
|
441
|
-
var onVisibilityChange = function onVisibilityChange() {
|
|
442
|
-
if (document.hidden || !missedWhileHidden) return;
|
|
443
|
-
missedWhileHidden = false;
|
|
444
|
-
safetyTick();
|
|
445
|
-
};
|
|
446
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
342
|
+
});
|
|
343
|
+
refreshLoopRef.current = loop;
|
|
447
344
|
return function () {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
clearInterval(interval);
|
|
451
|
-
clearInterval(safety);
|
|
452
|
-
if (timer !== null) clearTimeout(timer);
|
|
345
|
+
refreshLoopRef.current = null;
|
|
346
|
+
loop.stop();
|
|
453
347
|
};
|
|
454
348
|
}, [mountOverlay, props.disableRefresh]);
|
|
455
349
|
React.useEffect(function () {
|
|
@@ -533,14 +427,11 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
533
427
|
Internal.log.error("could not get draft mode status", res);
|
|
534
428
|
return;
|
|
535
429
|
}
|
|
536
|
-
setDraftMode(
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
}
|
|
542
|
-
return prev;
|
|
543
|
-
});
|
|
430
|
+
if (setDraftMode(res.json.draftMode)) {
|
|
431
|
+
var _refreshLoopRef$curre;
|
|
432
|
+
// What the server components read moved with it.
|
|
433
|
+
(_refreshLoopRef$curre = refreshLoopRef.current) === null || _refreshLoopRef$curre === void 0 || _refreshLoopRef$curre.refresh();
|
|
434
|
+
}
|
|
544
435
|
})["catch"](function (err) {
|
|
545
436
|
Internal.log.error("could not get draft mode status", err);
|
|
546
437
|
})["finally"](function () {
|
|
@@ -586,10 +477,12 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
586
477
|
window.dispatchEvent(new CustomEvent("val-overlay-spa", {
|
|
587
478
|
detail: {
|
|
588
479
|
type: "draftMode",
|
|
589
|
-
value: draftMode !== null && draftMode !== void 0 ? draftMode : false
|
|
480
|
+
value: draftMode !== null && draftMode !== void 0 ? draftMode : false,
|
|
481
|
+
holds: holds,
|
|
482
|
+
holdsVersions: holdsVersions
|
|
590
483
|
}
|
|
591
484
|
}));
|
|
592
|
-
}, [mountOverlay, draftMode, spaReady]);
|
|
485
|
+
}, [mountOverlay, draftMode, spaReady, holds, holdsVersions]);
|
|
593
486
|
React.useEffect(function () {
|
|
594
487
|
if (!mountOverlay) {
|
|
595
488
|
SET_AUTO_TAG_JSX_ENABLED(false);
|
|
@@ -597,45 +490,39 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
597
490
|
if (draftMode) {
|
|
598
491
|
SET_AUTO_TAG_JSX_ENABLED(true);
|
|
599
492
|
var reactServerComponentRefreshListener = function reactServerComponentRefreshListener(event) {
|
|
600
|
-
if (event instanceof CustomEvent) {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
window.dispatchEvent(new Event(VAL_EDIT_LANDED));
|
|
630
|
-
}
|
|
631
|
-
} else {
|
|
632
|
-
Internal.log.error("invalid event detail", event.detail);
|
|
633
|
-
}
|
|
493
|
+
if (!(event instanceof CustomEvent)) {
|
|
494
|
+
Internal.log.error("invalid custom event (val-event)", event);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
var outcome = applyValEvent(valStore, event.detail);
|
|
498
|
+
if (outcome.type === "synced") {
|
|
499
|
+
setDraftSourcesSynced(true);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (outcome.type === "confirmed") {
|
|
503
|
+
var _refreshLoopRef$curre2;
|
|
504
|
+
(_refreshLoopRef$curre2 = refreshLoopRef.current) === null || _refreshLoopRef$curre2 === void 0 || _refreshLoopRef$curre2.confirmed(outcome.seq);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
if (outcome.type === "invalid") {
|
|
508
|
+
Internal.log.error("invalid custom event details (val-event)", outcome.detail);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Not a refresh: the server may not have it yet. Only, before the
|
|
513
|
+
* Studio's first `confirmed`, that this page's render is behind
|
|
514
|
+
* what the Studio holds (`startRefreshLoop`). A module re-sent that
|
|
515
|
+
* the page already shows does not count.
|
|
516
|
+
*/
|
|
517
|
+
if (outcome.changed) {
|
|
518
|
+
if (outcome.fromPreviousStudio === true) {
|
|
519
|
+
var _refreshLoopRef$curre3;
|
|
520
|
+
// A Studio of the release before: it never confirms.
|
|
521
|
+
(_refreshLoopRef$curre3 = refreshLoopRef.current) === null || _refreshLoopRef$curre3 === void 0 || _refreshLoopRef$curre3.changedByPreviousStudio();
|
|
634
522
|
} else {
|
|
635
|
-
|
|
523
|
+
var _refreshLoopRef$curre4;
|
|
524
|
+
(_refreshLoopRef$curre4 = refreshLoopRef.current) === null || _refreshLoopRef$curre4 === void 0 || _refreshLoopRef$curre4.changed();
|
|
636
525
|
}
|
|
637
|
-
} else {
|
|
638
|
-
Internal.log.error("invalid custom event (val-event)", event);
|
|
639
526
|
}
|
|
640
527
|
};
|
|
641
528
|
window.addEventListener("val-event", reactServerComponentRefreshListener);
|
|
@@ -644,7 +531,7 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
644
531
|
};
|
|
645
532
|
}
|
|
646
533
|
}
|
|
647
|
-
}, [mountOverlay, draftMode
|
|
534
|
+
}, [mountOverlay, draftMode]);
|
|
648
535
|
React.useEffect(function () {
|
|
649
536
|
if (!mountOverlay) {
|
|
650
537
|
return;
|
|
@@ -728,6 +615,7 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
728
615
|
draftMode: draftMode,
|
|
729
616
|
draftModeReady: (_draftModeReady$curre2 = draftModeReady.current) === null || _draftModeReady$curre2 === void 0 ? void 0 : _draftModeReady$curre2.promise,
|
|
730
617
|
draftSourcesSynced: draftSourcesSynced,
|
|
618
|
+
serverDraft: hasDraft,
|
|
731
619
|
suspend: suspendActive,
|
|
732
620
|
store: valStore,
|
|
733
621
|
children: [props.children, dropZone !== null && !spaLoaded && mountOverlay &&
|
|
@@ -786,7 +674,9 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
786
674
|
})]
|
|
787
675
|
}), mountOverlay && isCanvas && /*#__PURE__*/jsx(ValCanvasBridge, {
|
|
788
676
|
draftMode: draftMode === true,
|
|
789
|
-
isRefreshing: isRefreshing
|
|
677
|
+
isRefreshing: isRefreshing,
|
|
678
|
+
holds: holds,
|
|
679
|
+
holdsVersions: holdsVersions
|
|
790
680
|
}), mountOverlay && iframeSrc && /*#__PURE__*/jsx("iframe", {
|
|
791
681
|
loading: "eager",
|
|
792
682
|
style: {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var internal = require('@valbuild/react/internal');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
|
+
|
|
14
|
+
var ValOverlayContext = /*#__PURE__*/React__default["default"].createContext({
|
|
15
|
+
store: undefined,
|
|
16
|
+
draftMode: false,
|
|
17
|
+
suspend: false,
|
|
18
|
+
draftModeReady: undefined,
|
|
19
|
+
draftSourcesSynced: false
|
|
20
|
+
});
|
|
21
|
+
function ValOverlayProvider(_ref) {
|
|
22
|
+
var store = _ref.store,
|
|
23
|
+
draftMode = _ref.draftMode,
|
|
24
|
+
suspend = _ref.suspend,
|
|
25
|
+
draftModeReady = _ref.draftModeReady,
|
|
26
|
+
draftSourcesSynced = _ref.draftSourcesSynced,
|
|
27
|
+
serverDraft = _ref.serverDraft,
|
|
28
|
+
children = _ref.children;
|
|
29
|
+
return /*#__PURE__*/jsxRuntime.jsx(ValOverlayContext.Provider, {
|
|
30
|
+
value: {
|
|
31
|
+
store: store,
|
|
32
|
+
draftMode: draftMode,
|
|
33
|
+
suspend: suspend,
|
|
34
|
+
draftModeReady: draftModeReady,
|
|
35
|
+
draftSourcesSynced: draftSourcesSynced,
|
|
36
|
+
serverDraft: serverDraft
|
|
37
|
+
},
|
|
38
|
+
children: children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var useValOverlayContext = function useValOverlayContext() {
|
|
42
|
+
return React__default["default"].useContext(ValOverlayContext);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Object.defineProperty(exports, 'ValExternalStore', {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return internal.ValExternalStore; }
|
|
48
|
+
});
|
|
49
|
+
exports.ValOverlayContext = ValOverlayContext;
|
|
50
|
+
exports.ValOverlayProvider = ValOverlayProvider;
|
|
51
|
+
exports.useValOverlayContext = useValOverlayContext;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var internal = require('@valbuild/react/internal');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
|
+
|
|
14
|
+
var ValOverlayContext = /*#__PURE__*/React__default["default"].createContext({
|
|
15
|
+
store: undefined,
|
|
16
|
+
draftMode: false,
|
|
17
|
+
suspend: false,
|
|
18
|
+
draftModeReady: undefined,
|
|
19
|
+
draftSourcesSynced: false
|
|
20
|
+
});
|
|
21
|
+
function ValOverlayProvider(_ref) {
|
|
22
|
+
var store = _ref.store,
|
|
23
|
+
draftMode = _ref.draftMode,
|
|
24
|
+
suspend = _ref.suspend,
|
|
25
|
+
draftModeReady = _ref.draftModeReady,
|
|
26
|
+
draftSourcesSynced = _ref.draftSourcesSynced,
|
|
27
|
+
serverDraft = _ref.serverDraft,
|
|
28
|
+
children = _ref.children;
|
|
29
|
+
return /*#__PURE__*/jsxRuntime.jsx(ValOverlayContext.Provider, {
|
|
30
|
+
value: {
|
|
31
|
+
store: store,
|
|
32
|
+
draftMode: draftMode,
|
|
33
|
+
suspend: suspend,
|
|
34
|
+
draftModeReady: draftModeReady,
|
|
35
|
+
draftSourcesSynced: draftSourcesSynced,
|
|
36
|
+
serverDraft: serverDraft
|
|
37
|
+
},
|
|
38
|
+
children: children
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var useValOverlayContext = function useValOverlayContext() {
|
|
42
|
+
return React__default["default"].useContext(ValOverlayContext);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Object.defineProperty(exports, 'ValExternalStore', {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return internal.ValExternalStore; }
|
|
48
|
+
});
|
|
49
|
+
exports.ValOverlayContext = ValOverlayContext;
|
|
50
|
+
exports.ValOverlayProvider = ValOverlayProvider;
|
|
51
|
+
exports.useValOverlayContext = useValOverlayContext;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
export { ValExternalStore } from '@valbuild/react/internal';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var ValOverlayContext = /*#__PURE__*/React.createContext({
|
|
7
|
+
store: undefined,
|
|
8
|
+
draftMode: false,
|
|
9
|
+
suspend: false,
|
|
10
|
+
draftModeReady: undefined,
|
|
11
|
+
draftSourcesSynced: false
|
|
12
|
+
});
|
|
13
|
+
function ValOverlayProvider(_ref) {
|
|
14
|
+
var store = _ref.store,
|
|
15
|
+
draftMode = _ref.draftMode,
|
|
16
|
+
suspend = _ref.suspend,
|
|
17
|
+
draftModeReady = _ref.draftModeReady,
|
|
18
|
+
draftSourcesSynced = _ref.draftSourcesSynced,
|
|
19
|
+
serverDraft = _ref.serverDraft,
|
|
20
|
+
children = _ref.children;
|
|
21
|
+
return /*#__PURE__*/jsx(ValOverlayContext.Provider, {
|
|
22
|
+
value: {
|
|
23
|
+
store: store,
|
|
24
|
+
draftMode: draftMode,
|
|
25
|
+
suspend: suspend,
|
|
26
|
+
draftModeReady: draftModeReady,
|
|
27
|
+
draftSourcesSynced: draftSourcesSynced,
|
|
28
|
+
serverDraft: serverDraft
|
|
29
|
+
},
|
|
30
|
+
children: children
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
var useValOverlayContext = function useValOverlayContext() {
|
|
34
|
+
return React.useContext(ValOverlayContext);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { ValOverlayContext, ValOverlayProvider, useValOverlayContext };
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var objectSpread2 = require('./objectSpread2-
|
|
6
|
+
var objectSpread2 = require('./objectSpread2-469273e9.cjs.prod.js');
|
|
7
7
|
var objectWithoutProperties = require('./objectWithoutProperties-107dcb46.cjs.prod.js');
|
|
8
8
|
var core = require('@valbuild/core');
|
|
9
9
|
var React = require('react');
|
|
10
10
|
var stega = require('@valbuild/react/stega');
|
|
11
11
|
var jsxRuntime = require('react/jsx-runtime');
|
|
12
|
-
require('./defineProperty-8951f469.cjs.prod.js');
|
|
13
12
|
|
|
14
13
|
var _excluded = ["src", "hls", "disableHotspot", "disableCaptions", "style", "width", "height"];
|
|
15
14
|
/**
|