@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.
Files changed (32) hide show
  1. package/CHANGELOG.md +187 -0
  2. package/README.md +11 -11
  3. package/client/dist/valbuild-tanstack-client.cjs.dev.js +100 -293
  4. package/client/dist/valbuild-tanstack-client.cjs.prod.js +100 -293
  5. package/client/dist/valbuild-tanstack-client.esm.js +99 -292
  6. package/dist/ValOverlayContext-1e50a557.cjs.prod.js +47 -0
  7. package/dist/ValOverlayContext-6826b4d9.esm.js +40 -0
  8. package/dist/ValOverlayContext-b18c2f18.cjs.dev.js +47 -0
  9. package/dist/declarations/src/ValDraft.d.ts +6 -50
  10. package/dist/declarations/src/ValModulesClient.d.ts +1 -3
  11. package/dist/declarations/src/ValProvider.d.ts +1 -1
  12. package/dist/declarations/src/client/initValClient.d.ts +25 -3
  13. package/dist/declarations/src/server/initValContent.d.ts +55 -169
  14. package/dist/{routeFromVal-06590f50.esm.js → routeFromVal-124235a5.esm.js} +3 -153
  15. package/dist/{routeFromVal-3c3915e2.cjs.dev.js → routeFromVal-2e834397.cjs.prod.js} +1 -156
  16. package/dist/{routeFromVal-b31a9e00.cjs.prod.js → routeFromVal-3d4d7c30.cjs.dev.js} +1 -156
  17. package/dist/{typeof-66e2d869.esm.js → typeof-3e1a1d11.esm.js} +1 -1
  18. package/dist/{typeof-8998e126.cjs.prod.js → typeof-56656438.cjs.prod.js} +0 -2
  19. package/dist/{typeof-dd0246a1.cjs.dev.js → typeof-bd6ec82c.cjs.dev.js} +0 -2
  20. package/dist/valbuild-tanstack.cjs.dev.js +162 -282
  21. package/dist/valbuild-tanstack.cjs.prod.js +162 -282
  22. package/dist/valbuild-tanstack.esm.js +162 -281
  23. package/dist/{version-3d755ee7.esm.js → version-2b3824bf.esm.js} +2 -19
  24. package/dist/{version-278a8d18.cjs.dev.js → version-8e19c405.cjs.dev.js} +1 -19
  25. package/dist/{version-30535975.cjs.prod.js → version-d46bc4bb.cjs.prod.js} +1 -19
  26. package/package.json +8 -8
  27. package/server/dist/valbuild-tanstack-server.cjs.dev.js +278 -1140
  28. package/server/dist/valbuild-tanstack-server.cjs.prod.js +278 -1140
  29. package/server/dist/valbuild-tanstack-server.esm.js +279 -1141
  30. package/dist/ValOverlayContext-198b4bd1.cjs.dev.js +0 -301
  31. package/dist/ValOverlayContext-6411bbe3.esm.js +0 -293
  32. package/dist/ValOverlayContext-d9b22d1a.cjs.prod.js +0 -301
@@ -1,301 +0,0 @@
1
- 'use strict';
2
-
3
- var _typeof = require('./typeof-8998e126.cjs.prod.js');
4
- var core = require('@valbuild/core');
5
- var patch = require('@valbuild/core/patch');
6
- var React = require('react');
7
- var jsxRuntime = require('react/jsx-runtime');
8
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
-
11
- var React__default = /*#__PURE__*/_interopDefault(React);
12
-
13
- function _classCallCheck(a, n) {
14
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
15
- }
16
-
17
- function _defineProperties(e, r) {
18
- for (var t = 0; t < r.length; t++) {
19
- var o = r[t];
20
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _typeof._toPropertyKey(o.key), o);
21
- }
22
- }
23
- function _createClass(e, r, t) {
24
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
25
- writable: !1
26
- }), e;
27
- }
28
-
29
- var LOAD_TIMEOUT_MS = 10000;
30
- var ValExternalStore = /*#__PURE__*/function () {
31
- function ValExternalStore() {
32
- var _this = this;
33
- _classCallCheck(this, ValExternalStore);
34
- _typeof._defineProperty(this, "listeners", void 0);
35
- _typeof._defineProperty(this, "loadPromises", void 0);
36
- // Path-keyed cache of every source seen via update(). The single source of
37
- // truth: load state and snapshots are both derived from this, so data can be
38
- // queried for any combination of paths even before a subscriber registers.
39
- _typeof._defineProperty(this, "loadedSources", void 0);
40
- // Reference-stable per-subscriberId snapshot cache for useSyncExternalStore.
41
- // Built lazily from loadedSources in get() and invalidated in update().
42
- _typeof._defineProperty(this, "snapshots", void 0);
43
- // One-shot listeners used solely by waitForLoad. Kept separate from the
44
- // useSyncExternalStore listeners so waitForLoad never has to register (and
45
- // leak) a subscriberId.
46
- _typeof._defineProperty(this, "loadListeners", void 0);
47
- _typeof._defineProperty(this, "subscribe", function (paths) {
48
- return function (listener) {
49
- var subscriberId = createSubscriberId(paths);
50
- var existing = _this.listeners.get(subscriberId);
51
- if (existing) {
52
- existing.push(listener);
53
- } else {
54
- _this.listeners.set(subscriberId, [listener]);
55
- }
56
- return function () {
57
- var current = _this.listeners.get(subscriberId);
58
- if (!current) return;
59
- var idx = current.indexOf(listener);
60
- if (idx >= 0) current.splice(idx, 1);
61
- if (current.length === 0) _this.listeners["delete"](subscriberId);
62
- };
63
- };
64
- });
65
- _typeof._defineProperty(this, "getSnapshot", function (paths) {
66
- return function () {
67
- return _this.get(paths);
68
- };
69
- });
70
- _typeof._defineProperty(this, "getServerSnapshot", function (paths) {
71
- return function () {
72
- return _this.get(paths);
73
- };
74
- });
75
- _typeof._defineProperty(this, "get", function (paths) {
76
- var subscriberId = createSubscriberId(paths);
77
- if (_this.snapshots.has(subscriberId)) {
78
- return _this.snapshots.get(subscriberId);
79
- }
80
- // Build the snapshot from the path-keyed loadedSources so data that arrived
81
- // before this subscriber registered is still returned. Cache it for a
82
- // reference-stable result (required by useSyncExternalStore).
83
- var record;
84
- var _iterator = _typeof._createForOfIteratorHelper(paths),
85
- _step;
86
- try {
87
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
88
- var p = _step.value;
89
- // Json never holds `undefined`, so a defined value means the path loaded.
90
- var loaded = _this.loadedSources.get(p);
91
- if (loaded !== undefined) {
92
- if (!record) {
93
- record = {};
94
- }
95
- record[p] = loaded;
96
- }
97
- }
98
- } catch (err) {
99
- _iterator.e(err);
100
- } finally {
101
- _iterator.f();
102
- }
103
- _this.snapshots.set(subscriberId, record);
104
- return record;
105
- });
106
- _typeof._defineProperty(this, "hasAllLoaded", function (paths) {
107
- var _iterator2 = _typeof._createForOfIteratorHelper(paths),
108
- _step2;
109
- try {
110
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
111
- var p = _step2.value;
112
- if (!_this.loadedSources.has(p)) {
113
- return false;
114
- }
115
- }
116
- } catch (err) {
117
- _iterator2.e(err);
118
- } finally {
119
- _iterator2.f();
120
- }
121
- return true;
122
- });
123
- /**
124
- * Returns a cached promise that resolves once `update()` has populated
125
- * every path in `paths`. The same promise instance is returned for the
126
- * same paths until it resolves — required so `React.use` / classic
127
- * Suspense doesn't re-suspend on every render.
128
- *
129
- * If the data never arrives (network failure, a path that is never
130
- * `update()`'d, a typo in a module path) the promise would otherwise hang
131
- * forever and keep the Suspense boundary in its fallback. To avoid a silent
132
- * hang it resolves anyway after `LOAD_TIMEOUT_MS`, logging an error so the
133
- * failure is diagnosable while the page still renders with partial data.
134
- */
135
- _typeof._defineProperty(this, "waitForLoad", function (paths) {
136
- if (_this.hasAllLoaded(paths)) {
137
- return Promise.resolve();
138
- }
139
- var subscriberId = createSubscriberId(paths);
140
- var existing = _this.loadPromises.get(subscriberId);
141
- if (existing) {
142
- return existing;
143
- }
144
- var promise = new Promise(function (resolve) {
145
- var cleanup = function cleanup() {
146
- clearTimeout(timeout);
147
- _this.loadListeners["delete"](listener);
148
- _this.loadPromises["delete"](subscriberId);
149
- };
150
- var listener = function listener() {
151
- if (_this.hasAllLoaded(paths)) {
152
- cleanup();
153
- resolve();
154
- }
155
- };
156
- var timeout = setTimeout(function () {
157
- var missing = paths.filter(function (p) {
158
- return !_this.loadedSources.has(p);
159
- });
160
- core.Internal.log.error("draft module(s) did not load within ".concat(LOAD_TIMEOUT_MS, "ms; rendering with partial data. Missing: ").concat(missing.join(", ")));
161
- cleanup();
162
- resolve();
163
- }, LOAD_TIMEOUT_MS);
164
- // Don't let the pending timer keep a Node process (e.g. the test runner
165
- // or SSR) alive; setTimeout returns a number in the browser, where there
166
- // is nothing to unref.
167
- if (typeof timeout !== "number") {
168
- timeout.unref();
169
- }
170
- _this.loadListeners.add(listener);
171
- });
172
- _this.loadPromises.set(subscriberId, promise);
173
- return promise;
174
- });
175
- this.listeners = new Map();
176
- this.loadPromises = new Map();
177
- this.loadedSources = new Map();
178
- this.snapshots = new Map();
179
- this.loadListeners = new Set();
180
- }
181
- return _createClass(ValExternalStore, [{
182
- key: "update",
183
- value:
184
- /**
185
- * Take a module's source from the editor.
186
- *
187
- * Returns whether this actually MOVED the value, which the caller needs and
188
- * cannot work out for itself: the same source arrives more than once by
189
- * design. The editor sends a catch-up snapshot of everything it holds every
190
- * time the page becomes a new document — a reload, or the one the dev server does
191
- * when a publish rewrites the `.val.ts` files — and most of that snapshot is
192
- * content this page already has.
193
- *
194
- * Without the answer, `ValTanStackProvider` armed its `router.invalidate()` loop on
195
- * the arrival rather than on the change, so every publish bought a whole-route
196
- * request whether or not the page was out of date. With auto-save on that is
197
- * one per pause in typing, which in development is a re-render (and sometimes
198
- * a recompile) of the page — and it is what leaves the canvas looking
199
- * permanently busy.
200
- */
201
- function update(path, source) {
202
- // `Json` has no `undefined`, so absent and "stored as undefined" cannot be
203
- // confused: a miss here means this page has never been given this module.
204
- var before = this.loadedSources.get(path);
205
- var changed = before === undefined || !patch.deepEqual(before, source);
206
- this.loadedSources.set(path, source);
207
- if (!changed) {
208
- // Nothing downstream to do: every subscriber's snapshot still answers
209
- // with the same value, so invalidating them would be a re-render that
210
- // shows exactly what is already on screen.
211
- return false;
212
- }
213
- // Invalidate cached snapshots that include this path so the next get()
214
- // rebuilds a fresh (new-reference) record, then notify their listeners.
215
- for (var _i = 0, _Array$from = Array.from(this.snapshots.keys()); _i < _Array$from.length; _i++) {
216
- var subscriberId = _Array$from[_i];
217
- if (subscriberId.includes(path)) {
218
- // TODO: hash paths instead
219
- this.snapshots["delete"](subscriberId);
220
- }
221
- }
222
- var _iterator3 = _typeof._createForOfIteratorHelper(this.listeners.keys()),
223
- _step3;
224
- try {
225
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
226
- var _subscriberId = _step3.value;
227
- if (_subscriberId.includes(path)) {
228
- this.emitChange(_subscriberId);
229
- }
230
- }
231
- } catch (err) {
232
- _iterator3.e(err);
233
- } finally {
234
- _iterator3.f();
235
- }
236
- for (var _i2 = 0, _Array$from2 = Array.from(this.loadListeners); _i2 < _Array$from2.length; _i2++) {
237
- var listener = _Array$from2[_i2];
238
- listener();
239
- }
240
- return true;
241
- }
242
- }, {
243
- key: "emitChange",
244
- value: function emitChange(subscriberId) {
245
- var _this$listeners$get;
246
- var _iterator4 = _typeof._createForOfIteratorHelper((_this$listeners$get = this.listeners.get(subscriberId)) !== null && _this$listeners$get !== void 0 ? _this$listeners$get : []),
247
- _step4;
248
- try {
249
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
250
- var listener = _step4.value;
251
- listener();
252
- }
253
- } catch (err) {
254
- _iterator4.e(err);
255
- } finally {
256
- _iterator4.f();
257
- }
258
- }
259
- }]);
260
- }();
261
- function createSubscriberId(paths) {
262
- return paths.slice().sort().join("&");
263
- }
264
- var ValOverlayContext = /*#__PURE__*/React__default["default"].createContext({
265
- store: undefined,
266
- draftMode: false,
267
- suspend: false,
268
- draftModeReady: undefined,
269
- draftSourcesSynced: false
270
- });
271
- function ValOverlayProvider(_ref) {
272
- var store = _ref.store,
273
- draftMode = _ref.draftMode,
274
- suspend = _ref.suspend,
275
- draftModeReady = _ref.draftModeReady,
276
- draftSourcesSynced = _ref.draftSourcesSynced,
277
- serverDraft = _ref.serverDraft,
278
- analytics = _ref.analytics,
279
- snapshot = _ref.snapshot,
280
- children = _ref.children;
281
- return /*#__PURE__*/jsxRuntime.jsx(ValOverlayContext.Provider, {
282
- value: {
283
- store: store,
284
- draftMode: draftMode,
285
- suspend: suspend,
286
- draftModeReady: draftModeReady,
287
- draftSourcesSynced: draftSourcesSynced,
288
- serverDraft: serverDraft,
289
- analytics: analytics,
290
- snapshot: snapshot
291
- },
292
- children: children
293
- });
294
- }
295
- var useValOverlayContext = function useValOverlayContext() {
296
- return React__default["default"].useContext(ValOverlayContext);
297
- };
298
-
299
- exports.ValExternalStore = ValExternalStore;
300
- exports.ValOverlayProvider = ValOverlayProvider;
301
- exports.useValOverlayContext = useValOverlayContext;