@valbuild/next 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 +163 -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-114c45b6.cjs.prod.js} +1 -1
- package/dist/{version-bfb6bbc0.cjs.prod.js → version-cc1bc4e5.cjs.dev.js} +1 -1
- package/dist/{version-8bac9fbe.esm.js → version-d8f64e54.esm.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
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var slicedToArray = require('./slicedToArray-
|
|
6
|
+
var slicedToArray = require('./slicedToArray-ed812733.cjs.dev.js');
|
|
7
7
|
var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
|
|
8
|
-
var objectSpread2 = require('./objectSpread2-
|
|
8
|
+
var objectSpread2 = require('./objectSpread2-58726b14.cjs.dev.js');
|
|
9
9
|
var core = require('@valbuild/core');
|
|
10
10
|
var ui = require('@valbuild/ui');
|
|
11
11
|
var navigation = require('next/navigation');
|
|
12
12
|
var Script = require('next/script');
|
|
13
13
|
var React = require('react');
|
|
14
|
-
var ValOverlayContext = require('./ValOverlayContext-
|
|
14
|
+
var ValOverlayContext = require('./ValOverlayContext-0c29b6a7.cjs.dev.js');
|
|
15
15
|
var stega = require('@valbuild/react/stega');
|
|
16
|
-
var
|
|
16
|
+
var internal = require('@valbuild/react/internal');
|
|
17
|
+
var fallbackColors = require('./fallbackColors-38f01ad2.cjs.dev.js');
|
|
17
18
|
var client = require('@valbuild/shared/client');
|
|
18
|
-
var createForOfIteratorHelper = require('./createForOfIteratorHelper-
|
|
19
|
-
var ValCanvasBridge = require('./ValCanvasBridge-
|
|
19
|
+
var createForOfIteratorHelper = require('./createForOfIteratorHelper-9c6aa3c7.cjs.dev.js');
|
|
20
|
+
var ValCanvasBridge = require('./ValCanvasBridge-4b81f653.cjs.dev.js');
|
|
20
21
|
var jsxRuntime = require('react/jsx-runtime');
|
|
21
|
-
require('./unsupportedIterableToArray-
|
|
22
|
-
require('./defineProperty-f90345d7.cjs.dev.js');
|
|
22
|
+
require('./unsupportedIterableToArray-20a9209f.cjs.dev.js');
|
|
23
23
|
|
|
24
24
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
25
25
|
|
|
@@ -96,82 +96,6 @@ function hasValEnableCookie(cookieString) {
|
|
|
96
96
|
return false;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/**
|
|
100
|
-
* Whether the page should re-read the server on its own, right now.
|
|
101
|
-
*
|
|
102
|
-
* The page cannot know when its own edit has been persisted. An edit is applied
|
|
103
|
-
* to the client store immediately and written to the server asynchronously, so
|
|
104
|
-
* a `router.refresh()` fired on the edit can reach a server that has not saved
|
|
105
|
-
* the patch yet: the payload comes back with the old content, and nothing
|
|
106
|
-
* schedules another look. What an editor sees is a canvas that flickered and did
|
|
107
|
-
* not change — which is indistinguishable from an edit that did not work.
|
|
108
|
-
*
|
|
109
|
-
* So the page asks again a little later. This is the "should I bother" half of
|
|
110
|
-
* that, kept out of the effect and pure so the reasons NOT to are checkable:
|
|
111
|
-
* every one of them is a whole-route request avoided, and in development Next
|
|
112
|
-
* re-renders (and sometimes recompiles) the page for each one.
|
|
113
|
-
*/
|
|
114
|
-
function shouldSafetyRefresh(state) {
|
|
115
|
-
// Never edited: a preview someone is only looking at has nothing to catch up
|
|
116
|
-
// on, and polling it would cost a route render per tick for nothing.
|
|
117
|
-
if (state.lastEditAt === 0) return false;
|
|
118
|
-
// The editing stopped long enough ago that anything in flight has landed.
|
|
119
|
-
if (state.now - state.lastEditAt > state.windowMs) return false;
|
|
120
|
-
// Nobody is looking. The caller refreshes once on the way back instead.
|
|
121
|
-
if (state.hidden) return false;
|
|
122
|
-
// Already on its way. Stacking whole-route requests makes the slowness this
|
|
123
|
-
// exists to paper over worse, not better.
|
|
124
|
-
if (state.isRefreshing) return false;
|
|
125
|
-
// One just went out — usually the edit-driven refresh, a moment ago.
|
|
126
|
-
if (state.now - state.lastRefreshAt < state.minIntervalMs) return false;
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
var REFRESH_INTERVAL_MS = 500;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* How often the page re-reads the server on its own, without being told to.
|
|
134
|
-
*
|
|
135
|
-
* A safety net for a race no amount of care on this side can close. An edit is
|
|
136
|
-
* applied to the client store immediately and saved to the server
|
|
137
|
-
* asynchronously, so `router.refresh()` fired on the edit can reach a server
|
|
138
|
-
* that has not written the patch yet: the RSC payload comes back with the old
|
|
139
|
-
* content, the counter has already been cleared, and nothing schedules another
|
|
140
|
-
* look. What you see is a canvas that flickered and did not change — which is
|
|
141
|
-
* indistinguishable from an edit that did not work.
|
|
142
|
-
*
|
|
143
|
-
* The honest fix would be for the page to know when its patch has been
|
|
144
|
-
* persisted, and it has no way to ask. So it asks again a little later instead.
|
|
145
|
-
*/
|
|
146
|
-
var SAFETY_REFRESH_MS = 10000;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* How long after an edit the safety net keeps looking.
|
|
150
|
-
*
|
|
151
|
-
* The reason to stop is that this is a whole-route request: in development Next
|
|
152
|
-
* re-renders (and sometimes recompiles) the page for every one, and a preview
|
|
153
|
-
* nobody is editing has nothing to catch up on. So the net is armed by editing
|
|
154
|
-
* and disarms itself when the editing stops — long enough after the last
|
|
155
|
-
* keystroke that any write still in flight has certainly landed.
|
|
156
|
-
*/
|
|
157
|
-
var SAFETY_REFRESH_WINDOW_MS = 30000;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Fired on this window when an edit has been applied to the client store.
|
|
161
|
-
*
|
|
162
|
-
* The refresh loop listens for it so it can start the round trip immediately
|
|
163
|
-
* rather than on its next tick. A DOM event rather than state, because the
|
|
164
|
-
* counter it accompanies is a ref and the loop lives in an effect that must not
|
|
165
|
-
* be torn down and rebuilt per keystroke.
|
|
166
|
-
*/
|
|
167
|
-
var VAL_EDIT_LANDED = "val-edit-landed";
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* How often `/draft/stat` is asked when nothing is in progress.
|
|
171
|
-
*
|
|
172
|
-
* Draft mode changes when someone toggles it, which the handshake below already
|
|
173
|
-
* covers — so this is only there to notice it being changed somewhere else.
|
|
174
|
-
*/
|
|
175
99
|
var DRAFT_IDLE_POLL_MS = 20000;
|
|
176
100
|
|
|
177
101
|
/**
|
|
@@ -198,7 +122,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
|
|
|
198
122
|
*/
|
|
199
123
|
var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
|
|
200
124
|
var ValNextProvider = function ValNextProvider(props) {
|
|
201
|
-
var _draftModeReady$curre2;
|
|
125
|
+
var _props$draft, _draftModeReady$curre2;
|
|
202
126
|
// TODO: use config:
|
|
203
127
|
var route = "/api/val";
|
|
204
128
|
/**
|
|
@@ -238,10 +162,32 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
238
162
|
}, _callee);
|
|
239
163
|
})), [route]);
|
|
240
164
|
|
|
165
|
+
/**
|
|
166
|
+
* The draft the page was rendered with, as it was at mount. A ref, not the
|
|
167
|
+
* prop: the server and the browser's first render must start from the
|
|
168
|
+
* same thing, and a later prop must not reset a store the overlay has been
|
|
169
|
+
* updating since. One that is not a draft (`draftMode: false`) is not one.
|
|
170
|
+
*/
|
|
171
|
+
var initialDraft = React__default["default"].useRef((_props$draft = props.draft) !== null && _props$draft !== void 0 ? _props$draft : null).current;
|
|
172
|
+
var hasDraft = internal.isDraft(initialDraft);
|
|
241
173
|
// TODO: move below into react package
|
|
242
174
|
var valStore = React__default["default"].useMemo(function () {
|
|
243
|
-
return
|
|
244
|
-
}, []);
|
|
175
|
+
return internal.createDraftStore(initialDraft);
|
|
176
|
+
}, [initialDraft]);
|
|
177
|
+
/**
|
|
178
|
+
* What this page reports to the Studio when it connects: the modules it
|
|
179
|
+
* was rendered with a draft of (`draftHolds`). The Studio sends each of
|
|
180
|
+
* them in its catch-up, so a draft that stopped being the draft before the
|
|
181
|
+
* Studio was there -- discarded, published -- does not stay on the page.
|
|
182
|
+
*/
|
|
183
|
+
var holds = React__default["default"].useMemo(function () {
|
|
184
|
+
return internal.draftHolds(initialDraft);
|
|
185
|
+
}, [initialDraft]);
|
|
186
|
+
// And the version of each, where the draft says: one the Studio would send
|
|
187
|
+
// at the same version is the same content, and is not sent again.
|
|
188
|
+
var holdsVersions = React__default["default"].useMemo(function () {
|
|
189
|
+
return internal.draftHoldsVersions(initialDraft);
|
|
190
|
+
}, [initialDraft]);
|
|
245
191
|
// Whether useValStega should actually suspend. False during SSR and the
|
|
246
192
|
// hydration render — the server store is never populated (draft data
|
|
247
193
|
// arrives via browser CustomEvents only), so suspending there would just
|
|
@@ -263,7 +209,9 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
263
209
|
* protocol. Without this the page could only wait out `waitForLoad`'s timeout,
|
|
264
210
|
* ten seconds per module nobody had edited.
|
|
265
211
|
*/
|
|
266
|
-
|
|
212
|
+
// A server-read draft is everything there is: a module missing from it has
|
|
213
|
+
// no changes, so there is nothing more to wait for.
|
|
214
|
+
var _React$useState3 = React__default["default"].useState(hasDraft),
|
|
267
215
|
_React$useState4 = slicedToArray._slicedToArray(_React$useState3, 2),
|
|
268
216
|
draftSourcesSynced = _React$useState4[0],
|
|
269
217
|
setDraftSourcesSynced = _React$useState4[1];
|
|
@@ -288,10 +236,30 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
288
236
|
_React$useState8 = slicedToArray._slicedToArray(_React$useState7, 2),
|
|
289
237
|
isCanvas = _React$useState8[0],
|
|
290
238
|
setIsCanvas = _React$useState8[1];
|
|
291
|
-
|
|
239
|
+
// Known on the server when it read a draft: a draft is only read in draft
|
|
240
|
+
// mode. Otherwise unknown until `/draft/stat` answers.
|
|
241
|
+
var _React$useState9 = React__default["default"].useState(hasDraft ? true : null),
|
|
292
242
|
_React$useState0 = slicedToArray._slicedToArray(_React$useState9, 2),
|
|
293
243
|
draftMode = _React$useState0[0],
|
|
294
|
-
|
|
244
|
+
setDraftModeState = _React$useState0[1];
|
|
245
|
+
/**
|
|
246
|
+
* `draftMode` as last set: what an answer from `/draft/stat` is compared
|
|
247
|
+
* with, to know whether it MOVED draft mode and so whether to refresh.
|
|
248
|
+
*
|
|
249
|
+
* Compared here, and the refresh sent after `setDraftMode`, rather than in
|
|
250
|
+
* a `setDraftMode` updater: React may call an updater twice (StrictMode)
|
|
251
|
+
* or during a render, and a refresh is a side effect -- run twice it is
|
|
252
|
+
* two refreshes, and run in a render it is a `startTransition` while
|
|
253
|
+
* rendering, which React refuses with a warning.
|
|
254
|
+
*/
|
|
255
|
+
var draftModeRef = React__default["default"].useRef(draftMode);
|
|
256
|
+
/** Set draft mode; `true` when that moved it. */
|
|
257
|
+
var setDraftMode = function setDraftMode(next) {
|
|
258
|
+
var moved = draftModeRef.current !== next;
|
|
259
|
+
draftModeRef.current = next;
|
|
260
|
+
setDraftModeState(next);
|
|
261
|
+
return moved;
|
|
262
|
+
};
|
|
295
263
|
/**
|
|
296
264
|
* Resolves when `draftMode` stops being unknown.
|
|
297
265
|
*
|
|
@@ -336,21 +304,16 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
336
304
|
isRefreshing = _React$useTransition2[0],
|
|
337
305
|
startTransition = _React$useTransition2[1];
|
|
338
306
|
/**
|
|
339
|
-
* The
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* owns the timers and the "when did we last edit" bookkeeping, and tearing
|
|
343
|
-
* that down mid-flurry loses it. A ref updated on render is the value without
|
|
344
|
-
* the dependency.
|
|
307
|
+
* The page's refresh loop, while the overlay is up: the `val-event`
|
|
308
|
+
* listener tells it what the Studio says. A ref, so the listener's effect
|
|
309
|
+
* is not rebuilt with it.
|
|
345
310
|
*/
|
|
346
|
-
var
|
|
347
|
-
var rerenderCounterRef = React__default["default"].useRef(0);
|
|
311
|
+
var refreshLoopRef = React__default["default"].useRef(null);
|
|
348
312
|
var _React$useState11 = React__default["default"].useState(null),
|
|
349
313
|
_React$useState12 = slicedToArray._slicedToArray(_React$useState11, 2),
|
|
350
314
|
iframeSrc = _React$useState12[0],
|
|
351
315
|
setIframeSrc = _React$useState12[1];
|
|
352
316
|
var pathname = navigation.usePathname();
|
|
353
|
-
isRefreshingRef.current = isRefreshing;
|
|
354
317
|
React.useEffect(function () {
|
|
355
318
|
window.dispatchEvent(new CustomEvent("val-provider:pathname", {
|
|
356
319
|
detail: pathname
|
|
@@ -375,7 +338,7 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
375
338
|
// suspends — no fallback flash — and the swap to draft data commits as a
|
|
376
339
|
// normal update instead of a hydration mismatch. Never deactivated:
|
|
377
340
|
// components must not stop suspending across renders (the draft-mode-off
|
|
378
|
-
// release valve lives in
|
|
341
|
+
// release valve lives in `overlaySource` instead).
|
|
379
342
|
if (props.suspend && shouldEnableVal()) {
|
|
380
343
|
startTransition(function () {
|
|
381
344
|
setSuspendActive(true);
|
|
@@ -384,99 +347,30 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
384
347
|
}, [props.suspend]);
|
|
385
348
|
|
|
386
349
|
/**
|
|
387
|
-
* Re-render the server tree when
|
|
350
|
+
* Re-render the server tree when the server has the editor's changes: once
|
|
351
|
+
* per version the Studio says it has confirmed (`startRefreshLoop`), never
|
|
352
|
+
* on a timer and never when an edit merely arrives -- arrived, it raced
|
|
353
|
+
* the write, and the server components came back without the edit.
|
|
388
354
|
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* the slow part in development. Refreshing on arrival and *then* enforcing the
|
|
393
|
-
* gap keeps the same ceiling on requests while removing the wait.
|
|
394
|
-
*
|
|
395
|
-
* Still a counter rather than a boolean: edits that arrive during the gap have
|
|
396
|
-
* to be picked up by the next refresh, and the count is what says whether
|
|
397
|
-
* there are any.
|
|
355
|
+
* `router.refresh()` does not say when it is done, so a version confirmed
|
|
356
|
+
* while one is on its way is a refresh of its own; the transition is what
|
|
357
|
+
* the canvas shows as busy (`isRefreshing`).
|
|
398
358
|
*/
|
|
399
359
|
React__default["default"].useEffect(function () {
|
|
400
360
|
if (!mountOverlay || props.disableRefresh) {
|
|
401
361
|
return;
|
|
402
362
|
}
|
|
403
|
-
var
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
var missedWhileHidden = false;
|
|
409
|
-
var refresh = function refresh() {
|
|
410
|
-
rerenderCounterRef.current = 0;
|
|
411
|
-
lastRefreshAt = Date.now();
|
|
412
|
-
startTransition(function () {
|
|
413
|
-
router.refresh();
|
|
414
|
-
});
|
|
415
|
-
};
|
|
416
|
-
var _tick = function tick() {
|
|
417
|
-
timer = null;
|
|
418
|
-
if (rerenderCounterRef.current === 0) return;
|
|
419
|
-
var since = Date.now() - lastRefreshAt;
|
|
420
|
-
if (since >= REFRESH_INTERVAL_MS) {
|
|
421
|
-
refresh();
|
|
422
|
-
} else {
|
|
423
|
-
timer = setTimeout(_tick, REFRESH_INTERVAL_MS - since);
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
var onEdit = function onEdit() {
|
|
427
|
-
lastEditAt = Date.now();
|
|
428
|
-
if (timer !== null) return;
|
|
429
|
-
timer = setTimeout(_tick, 0);
|
|
430
|
-
};
|
|
431
|
-
window.addEventListener(VAL_EDIT_LANDED, onEdit);
|
|
432
|
-
// A backstop for the counter being bumped without the event — the two are
|
|
433
|
-
// incremented in the same places today, but the poll is what made this
|
|
434
|
-
// correct regardless of who bumped it.
|
|
435
|
-
var interval = setInterval(_tick, REFRESH_INTERVAL_MS);
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* The safety net: look again, whether or not anything told us to.
|
|
439
|
-
*
|
|
440
|
-
* The reasons not to are in `shouldSafetyRefresh`, where they can be tested.
|
|
441
|
-
* `hidden` is the one this side has to remember something about: a skipped
|
|
442
|
-
* tick is worth one look when the tab comes back.
|
|
443
|
-
*/
|
|
444
|
-
var safetyTick = function safetyTick() {
|
|
445
|
-
if (document.hidden) {
|
|
446
|
-
missedWhileHidden = true;
|
|
447
|
-
return;
|
|
363
|
+
var loop = internal.startRefreshLoop({
|
|
364
|
+
refresh: function refresh() {
|
|
365
|
+
startTransition(function () {
|
|
366
|
+
router.refresh();
|
|
367
|
+
});
|
|
448
368
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
lastEditAt: lastEditAt,
|
|
452
|
-
lastRefreshAt: lastRefreshAt,
|
|
453
|
-
hidden: false,
|
|
454
|
-
isRefreshing: isRefreshingRef.current,
|
|
455
|
-
windowMs: SAFETY_REFRESH_WINDOW_MS,
|
|
456
|
-
minIntervalMs: REFRESH_INTERVAL_MS
|
|
457
|
-
});
|
|
458
|
-
if (go) refresh();
|
|
459
|
-
};
|
|
460
|
-
var safety = setInterval(safetyTick, SAFETY_REFRESH_MS);
|
|
461
|
-
/**
|
|
462
|
-
* Coming back to the tab is worth one look.
|
|
463
|
-
*
|
|
464
|
-
* Otherwise a background tab skips its ticks and then has to wait out a
|
|
465
|
-
* whole interval on return — which is exactly the moment someone is looking
|
|
466
|
-
* at the page to see whether their edit took.
|
|
467
|
-
*/
|
|
468
|
-
var onVisibilityChange = function onVisibilityChange() {
|
|
469
|
-
if (document.hidden || !missedWhileHidden) return;
|
|
470
|
-
missedWhileHidden = false;
|
|
471
|
-
safetyTick();
|
|
472
|
-
};
|
|
473
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
369
|
+
});
|
|
370
|
+
refreshLoopRef.current = loop;
|
|
474
371
|
return function () {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
clearInterval(interval);
|
|
478
|
-
clearInterval(safety);
|
|
479
|
-
if (timer !== null) clearTimeout(timer);
|
|
372
|
+
refreshLoopRef.current = null;
|
|
373
|
+
loop.stop();
|
|
480
374
|
};
|
|
481
375
|
}, [mountOverlay, props.disableRefresh]);
|
|
482
376
|
React__default["default"].useEffect(function () {
|
|
@@ -560,14 +454,11 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
560
454
|
core.Internal.log.error("could not get draft mode status", res);
|
|
561
455
|
return;
|
|
562
456
|
}
|
|
563
|
-
setDraftMode(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
}
|
|
569
|
-
return prev;
|
|
570
|
-
});
|
|
457
|
+
if (setDraftMode(res.json.draftMode)) {
|
|
458
|
+
var _refreshLoopRef$curre;
|
|
459
|
+
// What the server components read moved with it.
|
|
460
|
+
(_refreshLoopRef$curre = refreshLoopRef.current) === null || _refreshLoopRef$curre === void 0 || _refreshLoopRef$curre.refresh();
|
|
461
|
+
}
|
|
571
462
|
})["catch"](function (err) {
|
|
572
463
|
core.Internal.log.error("could not get draft mode status", err);
|
|
573
464
|
})["finally"](function () {
|
|
@@ -613,10 +504,12 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
613
504
|
window.dispatchEvent(new CustomEvent("val-overlay-spa", {
|
|
614
505
|
detail: {
|
|
615
506
|
type: "draftMode",
|
|
616
|
-
value: draftMode !== null && draftMode !== void 0 ? draftMode : false
|
|
507
|
+
value: draftMode !== null && draftMode !== void 0 ? draftMode : false,
|
|
508
|
+
holds: holds,
|
|
509
|
+
holdsVersions: holdsVersions
|
|
617
510
|
}
|
|
618
511
|
}));
|
|
619
|
-
}, [mountOverlay, draftMode, spaReady]);
|
|
512
|
+
}, [mountOverlay, draftMode, spaReady, holds, holdsVersions]);
|
|
620
513
|
React__default["default"].useEffect(function () {
|
|
621
514
|
if (!mountOverlay) {
|
|
622
515
|
stega.SET_AUTO_TAG_JSX_ENABLED(false);
|
|
@@ -624,45 +517,39 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
624
517
|
if (draftMode) {
|
|
625
518
|
stega.SET_AUTO_TAG_JSX_ENABLED(true);
|
|
626
519
|
var reactServerComponentRefreshListener = function reactServerComponentRefreshListener(event) {
|
|
627
|
-
if (event instanceof CustomEvent) {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
window.dispatchEvent(new Event(VAL_EDIT_LANDED));
|
|
657
|
-
}
|
|
658
|
-
} else {
|
|
659
|
-
core.Internal.log.error("invalid event detail", event.detail);
|
|
660
|
-
}
|
|
520
|
+
if (!(event instanceof CustomEvent)) {
|
|
521
|
+
core.Internal.log.error("invalid custom event (val-event)", event);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
var outcome = internal.applyValEvent(valStore, event.detail);
|
|
525
|
+
if (outcome.type === "synced") {
|
|
526
|
+
setDraftSourcesSynced(true);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (outcome.type === "confirmed") {
|
|
530
|
+
var _refreshLoopRef$curre2;
|
|
531
|
+
(_refreshLoopRef$curre2 = refreshLoopRef.current) === null || _refreshLoopRef$curre2 === void 0 || _refreshLoopRef$curre2.confirmed(outcome.seq);
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (outcome.type === "invalid") {
|
|
535
|
+
core.Internal.log.error("invalid custom event details (val-event)", outcome.detail);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Not a refresh: the server may not have it yet. Only, before the
|
|
540
|
+
* Studio's first `confirmed`, that this page's render is behind
|
|
541
|
+
* what the Studio holds (`startRefreshLoop`). A module re-sent that
|
|
542
|
+
* the page already shows does not count.
|
|
543
|
+
*/
|
|
544
|
+
if (outcome.changed) {
|
|
545
|
+
if (outcome.fromPreviousStudio === true) {
|
|
546
|
+
var _refreshLoopRef$curre3;
|
|
547
|
+
// A Studio of the release before: it never confirms.
|
|
548
|
+
(_refreshLoopRef$curre3 = refreshLoopRef.current) === null || _refreshLoopRef$curre3 === void 0 || _refreshLoopRef$curre3.changedByPreviousStudio();
|
|
661
549
|
} else {
|
|
662
|
-
|
|
550
|
+
var _refreshLoopRef$curre4;
|
|
551
|
+
(_refreshLoopRef$curre4 = refreshLoopRef.current) === null || _refreshLoopRef$curre4 === void 0 || _refreshLoopRef$curre4.changed();
|
|
663
552
|
}
|
|
664
|
-
} else {
|
|
665
|
-
core.Internal.log.error("invalid custom event (val-event)", event);
|
|
666
553
|
}
|
|
667
554
|
};
|
|
668
555
|
window.addEventListener("val-event", reactServerComponentRefreshListener);
|
|
@@ -671,7 +558,7 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
671
558
|
};
|
|
672
559
|
}
|
|
673
560
|
}
|
|
674
|
-
}, [mountOverlay, draftMode
|
|
561
|
+
}, [mountOverlay, draftMode]);
|
|
675
562
|
React__default["default"].useEffect(function () {
|
|
676
563
|
if (!mountOverlay) {
|
|
677
564
|
return;
|
|
@@ -755,6 +642,7 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
755
642
|
draftMode: draftMode,
|
|
756
643
|
draftModeReady: (_draftModeReady$curre2 = draftModeReady.current) === null || _draftModeReady$curre2 === void 0 ? void 0 : _draftModeReady$curre2.promise,
|
|
757
644
|
draftSourcesSynced: draftSourcesSynced,
|
|
645
|
+
serverDraft: hasDraft,
|
|
758
646
|
suspend: suspendActive,
|
|
759
647
|
store: valStore,
|
|
760
648
|
children: [props.children, dropZone !== null && !spaLoaded && mountOverlay &&
|
|
@@ -813,7 +701,9 @@ var ValNextProvider = function ValNextProvider(props) {
|
|
|
813
701
|
})]
|
|
814
702
|
}), mountOverlay && isCanvas && /*#__PURE__*/jsxRuntime.jsx(ValCanvasBridge.ValCanvasBridge, {
|
|
815
703
|
draftMode: draftMode === true,
|
|
816
|
-
isRefreshing: isRefreshing
|
|
704
|
+
isRefreshing: isRefreshing,
|
|
705
|
+
holds: holds,
|
|
706
|
+
holdsVersions: holdsVersions
|
|
817
707
|
}), mountOverlay && iframeSrc && /*#__PURE__*/jsxRuntime.jsx("iframe", {
|
|
818
708
|
loading: "eager",
|
|
819
709
|
style: {
|