@valbuild/tanstack 0.149.0 → 0.149.1

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @valbuild/tanstack
2
2
 
3
+ ## 0.149.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#916](https://github.com/valbuild/val/pull/916) [`f607bca`](https://github.com/valbuild/val/commit/f607bcae16723505fbd19bdfe791d3eaa1208524) Thanks [@freekh](https://github.com/freekh)! - Content analytics now works with nothing in the code: switching it on in a hosted project's settings is enough. With no `analytics` prop, `<ValProvider>` reads the setting itself -- the server render reads the `VAL_ANALYTICS` value Val's hosting hands the site, with the content version, and writes it into the page as a few bytes of JSON (`<script id="__val_analytics">`), which the browser reads back. Nothing is written while it is off.
8
+
9
+ A layout that passes `analytics={...}` from `fetchValAnalytics()` keeps working, and what it passes wins. The browser never reads `VAL_ANALYTICS` from the environment, so it needs no `VITE_` prefix and a build never fixes it: switching it off stops the counting without a rebuild.
10
+
11
+ - Updated dependencies [[`6777ea4`](https://github.com/valbuild/val/commit/6777ea42e3164e913381cccabb1bccca3cf58243), [`357bea6`](https://github.com/valbuild/val/commit/357bea6148467838819d46daa1fb575f41365185)]:
12
+ - @valbuild/ui@0.149.1
13
+ - @valbuild/react@0.149.1
14
+ - @valbuild/server@0.149.1
15
+ - @valbuild/language-server@0.149.1
16
+ - @valbuild/mcp@0.149.1
17
+
3
18
  ## 0.149.0
4
19
 
5
20
  ### Patch Changes
package/README.md CHANGED
@@ -387,10 +387,22 @@ Val can count which content your visitors see, on a site Val hosts. It is
387
387
  **off by default**, and a setting of the hosted project rather than of the
388
388
  code: the owner turns it on in the project's settings, and Val's hosting hands
389
389
  it to the site as the `VAL_ANALYTICS` variable, along with the id of the
390
- content version each page is rendered from. The `val.server.ts` the platform
391
- writes for a hosted project exports `fetchValAnalytics()`, which reads both
392
- into a `ValAnalytics`; pass that to the provider from the same loader as the
393
- draft:
390
+ content version each page is rendered from.
391
+
392
+ **A site needs no code for it.** With no `analytics` prop, `<ValProvider>`
393
+ reads the setting itself: the server render reads what the platform handed it
394
+ and writes it into the page as a few bytes of JSON, and the browser reads it
395
+ back. So switching it on or off in the project's settings is all it takes --
396
+ no rebuild, and nothing in the layout. While it is off, nothing is written.
397
+
398
+ It is never read in the browser from the environment, and needs no `VITE_`
399
+ prefix: a variable the browser could read is baked into the bundle when it is
400
+ built, which would make it a second switch, in the code, that keeps counting
401
+ after the owner has turned it off.
402
+
403
+ To decide in the code instead, pass it: the `val.server.ts` the platform
404
+ writes for a hosted project exports `fetchValAnalytics()`, which reads the
405
+ same two values into a `ValAnalytics`, and what is passed wins.
394
406
 
395
407
  ```tsx
396
408
  // src/routes/_site.tsx
@@ -418,18 +430,17 @@ function SiteLayout() {
418
430
  ```
419
431
 
420
432
  With it on, content read with the hooks is tagged for every visitor after
421
- hydration, so each element showing content carries a `data-val-path` to count.
422
- The HTML the server sends is the same with it on or off. A small script,
423
- loaded after hydration, then counts what each page rendered and what was on
424
- screen, and sends it to `/api/val/analytics` with the content version, so a
425
- page can be compared before and after a publish. No cookies, no storage and no
426
- visitor IDs, and nothing is sent in draft mode, in the Studio or from an
427
- automated browser.
428
-
429
- `fetchValAnalytics` is not part of `initValContent`: it exists in the file the
430
- platform writes, and nowhere else. A site Val does not host has nowhere to send
431
- counts yet, so it leaves `analytics` out. To see the mode working in local
432
- development, write your own -- `examples/tanstack/src/val/server.ts` reads
433
+ hydration, so each element showing content carries a `data-val-path` to count
434
+ (look for it in the browser's element inspector: it is not in the HTML the
435
+ server sends). A small script, loaded after hydration, then counts what each
436
+ page rendered and what was on screen, and sends it to `/api/val/analytics` with
437
+ the content version, so a page can be compared before and after a publish. No
438
+ cookies, no storage and no visitor IDs, and nothing is sent in draft mode, in
439
+ the Studio or from an automated browser.
440
+
441
+ A site Val does not host has nowhere to send counts yet, and nothing hands it
442
+ the setting, so it stays off. To see the mode working in local development,
443
+ pass `analytics` yourself -- `examples/tanstack/src/val/server.ts` reads
433
444
  `VAL_ANALYTICS` from `process.env`, which TanStack Start fills from
434
445
  `.env.development`.
435
446
 
@@ -48,8 +48,10 @@ function useHydrated() {
48
48
  *
49
49
  * With analytics on and draft mode off, the same rule for every visitor: no
50
50
  * tags on the server or while hydrating, tags from the render after. So the
51
- * HTML a visitor is sent, prerendered or not, is the same with analytics on or
52
- * off, and no edit tag ever reaches a crawler that does not run the page.
51
+ * content of the HTML a visitor is sent, prerendered or not, is the same with
52
+ * analytics on or off -- what differs is the few bytes of JSON that say it is
53
+ * on (`platformAnalytics.tsx`) -- and no edit tag ever reaches a crawler that
54
+ * does not run the page.
53
55
  *
54
56
  * Because JSX auto-tagging turns a tagged string into a `data-val-path`
55
57
  * attribute as the element is created, and the switch for it is process-wide.
@@ -48,8 +48,10 @@ function useHydrated() {
48
48
  *
49
49
  * With analytics on and draft mode off, the same rule for every visitor: no
50
50
  * tags on the server or while hydrating, tags from the render after. So the
51
- * HTML a visitor is sent, prerendered or not, is the same with analytics on or
52
- * off, and no edit tag ever reaches a crawler that does not run the page.
51
+ * content of the HTML a visitor is sent, prerendered or not, is the same with
52
+ * analytics on or off -- what differs is the few bytes of JSON that say it is
53
+ * on (`platformAnalytics.tsx`) -- and no edit tag ever reaches a crawler that
54
+ * does not run the page.
53
55
  *
54
56
  * Because JSX auto-tagging turns a tagged string into a `data-val-path`
55
57
  * attribute as the element is created, and the switch for it is process-wide.
@@ -40,8 +40,10 @@ function useHydrated() {
40
40
  *
41
41
  * With analytics on and draft mode off, the same rule for every visitor: no
42
42
  * tags on the server or while hydrating, tags from the render after. So the
43
- * HTML a visitor is sent, prerendered or not, is the same with analytics on or
44
- * off, and no edit tag ever reaches a crawler that does not run the page.
43
+ * content of the HTML a visitor is sent, prerendered or not, is the same with
44
+ * analytics on or off -- what differs is the few bytes of JSON that say it is
45
+ * on (`platformAnalytics.tsx`) -- and no edit tag ever reaches a crawler that
46
+ * does not run the page.
45
47
  *
46
48
  * Because JSX auto-tagging turns a tagged string into a `data-val-path`
47
49
  * attribute as the element is created, and the switch for it is process-wide.
@@ -2,11 +2,12 @@
2
2
  * What `<ValProvider analytics>` is handed: whether content analytics is on
3
3
  * for this site, and the content version the page is rendered from.
4
4
  *
5
- * Both come from the server, read in the site layout's loader. On a site Val
6
- * hosts, `fetchValAnalytics()` in the `val.server.ts` the platform writes
7
- * reads them from what the platform hands each render: the project's
5
+ * Both come from what Val's hosting hands each render: the project's
8
6
  * `VAL_ANALYTICS` setting, and `VAL_CONTENT_VERSION`, the id of the content
9
- * version being served.
7
+ * version being served. A provider that is passed nothing reads them itself
8
+ * (`platformAnalytics.tsx`); a layout that wants to decide reads them in its
9
+ * loader with `fetchValAnalytics()`, from the `val.server.ts` the platform
10
+ * writes, and passes them.
10
11
  */
11
12
  export type ValAnalytics = {
12
13
  /** Off unless this says so. */
@@ -6,7 +6,7 @@ var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
6
6
  var _typeof = require('./typeof-dd0246a1.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
9
- var version = require('./version-3ad556b9.cjs.dev.js');
9
+ var version = require('./version-f09c0421.cjs.dev.js');
10
10
  var internal = require('@valbuild/react/internal');
11
11
  var ui = require('@valbuild/ui');
12
12
  var reactRouter = require('@tanstack/react-router');
@@ -871,15 +871,115 @@ function shouldSafetyRefresh(state) {
871
871
  }
872
872
 
873
873
  /**
874
- * Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
874
+ * Content analytics as Val's hosting sets it, for a site whose layout passes
875
+ * `<ValProvider>` no `analytics` of its own.
876
+ *
877
+ * Switching analytics on in a hosted project's settings sets the project's
878
+ * `VAL_ANALYTICS` secret, and the platform starts the site's isolates again
879
+ * with it -- along with `VAL_CONTENT_VERSION`, the id of the content version
880
+ * they serve. Both arrive in `globalThis.__PLATFORM_SECRETS`. Reading them
881
+ * here, rather than only in the layout's loader (`fetchValAnalytics()`), is
882
+ * what makes the switch enough on its own: a site needs no code for it.
883
+ *
884
+ * The server render reads them and writes what it read into the page, as a
885
+ * few bytes of JSON; the browser reads that back. Nothing is written while
886
+ * analytics is off, so the page is the same as without Val's hosting.
887
+ *
888
+ * Only what the platform HANDED this isolate is read, never `process.env`:
889
+ * that is baked into the bundle at build time, and a `VAL_ANALYTICS` there
890
+ * would be a second switch, in the code, that keeps counting after the owner
891
+ * has turned it off.
892
+ */
893
+
894
+ /** The element the server render writes the setting into. */
895
+ var PLATFORM_ANALYTICS_ID = "__val_analytics";
896
+
897
+ /**
898
+ * One secret the platform handed this isolate, when it is one of Val's.
899
+ * Read off the object as it is, the way the generated `fetchValAnalytics()`
900
+ * does, so the two cannot disagree about what was handed over.
875
901
  */
902
+ function platformSecret(name) {
903
+ var handed = Reflect.get(globalThis, "__PLATFORM_SECRETS");
904
+ return _typeof._typeof(handed) === "object" && handed !== null ? Reflect.get(handed, name) : undefined;
905
+ }
906
+
907
+ /** The setting the platform handed this isolate; null when it is not on. */
908
+ function analyticsFromPlatform() {
909
+ if (platformSecret("VAL_ANALYTICS") !== "true") return null;
910
+ var contentVersion = platformSecret("VAL_CONTENT_VERSION");
911
+ return _typeof._objectSpread2({
912
+ enabled: true
913
+ }, typeof contentVersion === "string" && contentVersion !== "" ? {
914
+ contentVersion: contentVersion
915
+ } : {});
916
+ }
917
+
876
918
  /**
877
- * The floor between server re-renders.
919
+ * What the page said, once it said it. The element lives inside the provider,
920
+ * so a client navigation that unmounts the provider takes it with it, and the
921
+ * provider mounted again must still know: the page did not stop being one
922
+ * with analytics on. A page load starts this module again.
878
923
  *
879
- * `router.invalidate()` re-runs every loader of the current match tree — there
880
- * is no per-module invalidation — so this is about not queueing a round trip
881
- * per keystroke, not about batching for its own sake.
924
+ * It is the page's setting, so it reaches every provider on the page that is
925
+ * not told otherwise -- one that is passed `analytics`, on the server and in
926
+ * the browser, decides for itself.
927
+ */
928
+ var readFromPage = null;
929
+
930
+ /** The setting the server render wrote into this page; null when it wrote none. */
931
+ function analyticsFromPage() {
932
+ if (readFromPage !== null) return readFromPage;
933
+ var element = document.getElementById(PLATFORM_ANALYTICS_ID);
934
+ if (element === null) return null;
935
+ var value;
936
+ try {
937
+ var _element$textContent;
938
+ value = JSON.parse((_element$textContent = element.textContent) !== null && _element$textContent !== void 0 ? _element$textContent : "");
939
+ } catch (_unused) {
940
+ return null;
941
+ }
942
+ if (_typeof._typeof(value) !== "object" || value === null || !("enabled" in value) || value.enabled !== true) {
943
+ return null;
944
+ }
945
+ var contentVersion = "contentVersion" in value && typeof value.contentVersion === "string" ? value.contentVersion : undefined;
946
+ readFromPage = _typeof._objectSpread2({
947
+ enabled: true
948
+ }, contentVersion !== undefined ? {
949
+ contentVersion: contentVersion
950
+ } : {});
951
+ return readFromPage;
952
+ }
953
+
954
+ /** On the server, what the platform handed it; in the browser, what the server wrote. */
955
+ function analyticsOfThisPage() {
956
+ return typeof document === "undefined" ? analyticsFromPlatform() : analyticsFromPage();
957
+ }
958
+
959
+ /**
960
+ * The setting as JSON that can sit inside a `<script>`: a `<` is written as
961
+ * `\u003c`, so nothing in it can end the element.
962
+ */
963
+ function embeddableJson(value) {
964
+ return JSON.stringify(value).replace(/</g, "\\u003c");
965
+ }
966
+
967
+ /**
968
+ * Where the server render leaves the setting for the browser. Rendered the
969
+ * same on both sides -- the browser renders what it read -- so it hydrates
970
+ * without a mismatch.
882
971
  */
972
+ function PlatformAnalytics(_ref) {
973
+ var value = _ref.value;
974
+ return /*#__PURE__*/jsxRuntime.jsx("script", {
975
+ type: "application/json",
976
+ id: PLATFORM_ANALYTICS_ID,
977
+ dangerouslySetInnerHTML: {
978
+ __html: embeddableJson(value)
979
+ }
980
+ });
981
+ }
982
+
883
983
  var REFRESH_INTERVAL_MS = 500;
884
984
 
885
985
  /**
@@ -951,7 +1051,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
951
1051
  */
952
1052
  var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
953
1053
  var ValTanStackProvider = function ValTanStackProvider(props) {
954
- var _props$draft, _props$analytics, _draftModeReady$curre2;
1054
+ var _props$draft, _draftModeReady$curre2;
955
1055
  // TODO: use config:
956
1056
  var route = "/api/val";
957
1057
  /**
@@ -1010,8 +1110,25 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1010
1110
  * As the page was rendered. A ref, not the prop, for the reason
1011
1111
  * `initialDraft` is one: a later render's prop is a client navigation's
1012
1112
  * loader, which reads nothing.
1113
+ *
1114
+ * A layout that passes nothing gets the project's setting from Val's
1115
+ * hosting itself (`platformAnalytics.tsx`): the server render reads what
1116
+ * the platform handed it and writes it into the page, and the browser
1117
+ * reads it back. So switching analytics on in the project's settings is
1118
+ * enough; the layout does not have to read it.
1013
1119
  */
1014
- var analyticsSetting = React__default["default"].useRef((_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : null).current;
1120
+ // Not in a demo: its `/api/val` is static files, with nowhere to count.
1121
+ var _React$useState = React__default["default"].useState(function () {
1122
+ return props.analytics === undefined && !props.demo ? analyticsOfThisPage() : null;
1123
+ }),
1124
+ _React$useState2 = _typeof._slicedToArray(_React$useState, 1),
1125
+ platformAnalytics = _React$useState2[0];
1126
+ var _React$useState3 = React__default["default"].useState(function () {
1127
+ var _props$analytics;
1128
+ return (_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : platformAnalytics;
1129
+ }),
1130
+ _React$useState4 = _typeof._slicedToArray(_React$useState3, 1),
1131
+ analyticsSetting = _React$useState4[0];
1015
1132
  var analytics = (analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.enabled) === true;
1016
1133
  var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
1017
1134
  var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
@@ -1049,10 +1166,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1049
1166
  // transition: React keeps the static content visible while hooks suspend
1050
1167
  // and then swaps to draft data as a normal update — no Suspense fallback
1051
1168
  // flash and no hydration mismatch.
1052
- var _React$useState = React__default["default"].useState(false),
1053
- _React$useState2 = _typeof._slicedToArray(_React$useState, 2),
1054
- suspendActive = _React$useState2[0],
1055
- setSuspendActive = _React$useState2[1];
1169
+ var _React$useState5 = React__default["default"].useState(false),
1170
+ _React$useState6 = _typeof._slicedToArray(_React$useState5, 2),
1171
+ suspendActive = _React$useState6[0],
1172
+ setSuspendActive = _React$useState6[1];
1056
1173
  /**
1057
1174
  * Whether the studio has said it sent everything it holds.
1058
1175
  *
@@ -1063,14 +1180,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1063
1180
  */
1064
1181
  // A server-read draft is everything there is: a module missing from it has
1065
1182
  // no changes, so there is nothing more to wait for.
1066
- var _React$useState3 = React__default["default"].useState(hasDraft),
1067
- _React$useState4 = _typeof._slicedToArray(_React$useState3, 2),
1068
- draftSourcesSynced = _React$useState4[0],
1069
- setDraftSourcesSynced = _React$useState4[1];
1070
- var _React$useState5 = React__default["default"].useState(),
1071
- _React$useState6 = _typeof._slicedToArray(_React$useState5, 2),
1072
- mountOverlay = _React$useState6[0],
1073
- setMountOverlay = _React$useState6[1];
1183
+ var _React$useState7 = React__default["default"].useState(hasDraft),
1184
+ _React$useState8 = _typeof._slicedToArray(_React$useState7, 2),
1185
+ draftSourcesSynced = _React$useState8[0],
1186
+ setDraftSourcesSynced = _React$useState8[1];
1187
+ var _React$useState9 = React__default["default"].useState(),
1188
+ _React$useState0 = _typeof._slicedToArray(_React$useState9, 2),
1189
+ mountOverlay = _React$useState0[0],
1190
+ setMountOverlay = _React$useState0[1];
1074
1191
  /**
1075
1192
  * Whether this document is the studio's canvas frame.
1076
1193
  *
@@ -1084,16 +1201,16 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1084
1201
  * Read once, in the same effect as `mountOverlay`: it is a property of how
1085
1202
  * the document was loaded, and it cannot change without a navigation.
1086
1203
  */
1087
- var _React$useState7 = React__default["default"].useState(false),
1088
- _React$useState8 = _typeof._slicedToArray(_React$useState7, 2),
1089
- isCanvas = _React$useState8[0],
1090
- setIsCanvas = _React$useState8[1];
1204
+ var _React$useState1 = React__default["default"].useState(false),
1205
+ _React$useState10 = _typeof._slicedToArray(_React$useState1, 2),
1206
+ isCanvas = _React$useState10[0],
1207
+ setIsCanvas = _React$useState10[1];
1091
1208
  // Known on the server when it read a draft: `fetchValDraft` only reads one
1092
1209
  // in draft mode. Otherwise unknown until `/draft/stat` answers.
1093
- var _React$useState9 = React__default["default"].useState(hasDraft ? true : null),
1094
- _React$useState0 = _typeof._slicedToArray(_React$useState9, 2),
1095
- draftMode = _React$useState0[0],
1096
- setDraftMode = _React$useState0[1];
1210
+ var _React$useState11 = React__default["default"].useState(hasDraft ? true : null),
1211
+ _React$useState12 = _typeof._slicedToArray(_React$useState11, 2),
1212
+ draftMode = _React$useState12[0],
1213
+ setDraftMode = _React$useState12[1];
1097
1214
  /**
1098
1215
  * Resolves when `draftMode` stops being unknown.
1099
1216
  *
@@ -1128,10 +1245,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1128
1245
  (_draftModeReady$curre = draftModeReady.current) === null || _draftModeReady$curre === void 0 || _draftModeReady$curre.resolve();
1129
1246
  }
1130
1247
  }, [draftMode]);
1131
- var _React$useState1 = React__default["default"].useState(false),
1132
- _React$useState10 = _typeof._slicedToArray(_React$useState1, 2),
1133
- spaReady = _React$useState10[0],
1134
- setSpaReady = _React$useState10[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
1248
+ var _React$useState13 = React__default["default"].useState(false),
1249
+ _React$useState14 = _typeof._slicedToArray(_React$useState13, 2),
1250
+ spaReady = _React$useState14[0],
1251
+ setSpaReady = _React$useState14[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
1135
1252
  var router = reactRouter.useRouter();
1136
1253
  var _React$useTransition = React__default["default"].useTransition(),
1137
1254
  _React$useTransition2 = _typeof._slicedToArray(_React$useTransition, 2),
@@ -1147,10 +1264,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1147
1264
  */
1148
1265
  var isRefreshingRef = React__default["default"].useRef(false);
1149
1266
  var rerenderCounterRef = React__default["default"].useRef(0);
1150
- var _React$useState11 = React__default["default"].useState(null),
1151
- _React$useState12 = _typeof._slicedToArray(_React$useState11, 2),
1152
- iframeSrc = _React$useState12[0],
1153
- setIframeSrc = _React$useState12[1];
1267
+ var _React$useState15 = React__default["default"].useState(null),
1268
+ _React$useState16 = _typeof._slicedToArray(_React$useState15, 2),
1269
+ iframeSrc = _React$useState16[0],
1270
+ setIframeSrc = _React$useState16[1];
1154
1271
  var pathname = reactRouter.useRouterState({
1155
1272
  select: function select(state) {
1156
1273
  return state.location.pathname;
@@ -1595,10 +1712,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1595
1712
  window.dispatchEvent(new CustomEvent("val-append-overlay"));
1596
1713
  }
1597
1714
  });
1598
- var _React$useState13 = React__default["default"].useState(null),
1599
- _React$useState14 = _typeof._slicedToArray(_React$useState13, 2),
1600
- dropZone = _React$useState14[0],
1601
- setDropZone = _React$useState14[1];
1715
+ var _React$useState17 = React__default["default"].useState(null),
1716
+ _React$useState18 = _typeof._slicedToArray(_React$useState17, 2),
1717
+ dropZone = _React$useState18[0],
1718
+ setDropZone = _React$useState18[1];
1602
1719
  React__default["default"].useEffect(function () {
1603
1720
  var storedDropZone = localStorage.getItem("val-menu-drop-zone-default");
1604
1721
  if (storedDropZone) {
@@ -1611,10 +1728,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1611
1728
  var initTheme = React__default["default"].useMemo(function () {
1612
1729
  return initSessionTheme(props.config);
1613
1730
  }, [props.config]);
1614
- var _React$useState15 = React__default["default"].useState(false),
1615
- _React$useState16 = _typeof._slicedToArray(_React$useState15, 2),
1616
- spaLoaded = _React$useState16[0],
1617
- setSpaLoaded = _React$useState16[1];
1731
+ var _React$useState19 = React__default["default"].useState(false),
1732
+ _React$useState20 = _typeof._slicedToArray(_React$useState19, 2),
1733
+ spaLoaded = _React$useState20[0],
1734
+ setSpaLoaded = _React$useState20[1];
1618
1735
  React__default["default"].useEffect(function () {
1619
1736
  var listener = function listener() {
1620
1737
  setSpaLoaded(true);
@@ -1662,7 +1779,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1662
1779
  snapshot: snapshot,
1663
1780
  suspend: suspendActive,
1664
1781
  store: valStore,
1665
- children: [props.children, dropZone !== null && !spaLoaded && mountOverlay &&
1782
+ children: [props.children, platformAnalytics !== null && /*#__PURE__*/jsxRuntime.jsx(PlatformAnalytics, {
1783
+ value: platformAnalytics
1784
+ }), dropZone !== null && !spaLoaded && mountOverlay &&
1666
1785
  // The canvas frame loads no SPA, so its pill would spin for ever.
1667
1786
  !isCanvas && initTheme !== null && /*#__PURE__*/jsxRuntime.jsxs(React__default["default"].Fragment, {
1668
1787
  children: [/*#__PURE__*/jsxRuntime.jsx("style", {
@@ -6,7 +6,7 @@ var asyncToGenerator = require('./asyncToGenerator-8e5c36c8.cjs.prod.js');
6
6
  var _typeof = require('./typeof-8998e126.cjs.prod.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
9
- var version = require('./version-63cad8df.cjs.prod.js');
9
+ var version = require('./version-68b769fa.cjs.prod.js');
10
10
  var internal = require('@valbuild/react/internal');
11
11
  var ui = require('@valbuild/ui');
12
12
  var reactRouter = require('@tanstack/react-router');
@@ -871,15 +871,115 @@ function shouldSafetyRefresh(state) {
871
871
  }
872
872
 
873
873
  /**
874
- * Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
874
+ * Content analytics as Val's hosting sets it, for a site whose layout passes
875
+ * `<ValProvider>` no `analytics` of its own.
876
+ *
877
+ * Switching analytics on in a hosted project's settings sets the project's
878
+ * `VAL_ANALYTICS` secret, and the platform starts the site's isolates again
879
+ * with it -- along with `VAL_CONTENT_VERSION`, the id of the content version
880
+ * they serve. Both arrive in `globalThis.__PLATFORM_SECRETS`. Reading them
881
+ * here, rather than only in the layout's loader (`fetchValAnalytics()`), is
882
+ * what makes the switch enough on its own: a site needs no code for it.
883
+ *
884
+ * The server render reads them and writes what it read into the page, as a
885
+ * few bytes of JSON; the browser reads that back. Nothing is written while
886
+ * analytics is off, so the page is the same as without Val's hosting.
887
+ *
888
+ * Only what the platform HANDED this isolate is read, never `process.env`:
889
+ * that is baked into the bundle at build time, and a `VAL_ANALYTICS` there
890
+ * would be a second switch, in the code, that keeps counting after the owner
891
+ * has turned it off.
892
+ */
893
+
894
+ /** The element the server render writes the setting into. */
895
+ var PLATFORM_ANALYTICS_ID = "__val_analytics";
896
+
897
+ /**
898
+ * One secret the platform handed this isolate, when it is one of Val's.
899
+ * Read off the object as it is, the way the generated `fetchValAnalytics()`
900
+ * does, so the two cannot disagree about what was handed over.
875
901
  */
902
+ function platformSecret(name) {
903
+ var handed = Reflect.get(globalThis, "__PLATFORM_SECRETS");
904
+ return _typeof._typeof(handed) === "object" && handed !== null ? Reflect.get(handed, name) : undefined;
905
+ }
906
+
907
+ /** The setting the platform handed this isolate; null when it is not on. */
908
+ function analyticsFromPlatform() {
909
+ if (platformSecret("VAL_ANALYTICS") !== "true") return null;
910
+ var contentVersion = platformSecret("VAL_CONTENT_VERSION");
911
+ return _typeof._objectSpread2({
912
+ enabled: true
913
+ }, typeof contentVersion === "string" && contentVersion !== "" ? {
914
+ contentVersion: contentVersion
915
+ } : {});
916
+ }
917
+
876
918
  /**
877
- * The floor between server re-renders.
919
+ * What the page said, once it said it. The element lives inside the provider,
920
+ * so a client navigation that unmounts the provider takes it with it, and the
921
+ * provider mounted again must still know: the page did not stop being one
922
+ * with analytics on. A page load starts this module again.
878
923
  *
879
- * `router.invalidate()` re-runs every loader of the current match tree — there
880
- * is no per-module invalidation — so this is about not queueing a round trip
881
- * per keystroke, not about batching for its own sake.
924
+ * It is the page's setting, so it reaches every provider on the page that is
925
+ * not told otherwise -- one that is passed `analytics`, on the server and in
926
+ * the browser, decides for itself.
927
+ */
928
+ var readFromPage = null;
929
+
930
+ /** The setting the server render wrote into this page; null when it wrote none. */
931
+ function analyticsFromPage() {
932
+ if (readFromPage !== null) return readFromPage;
933
+ var element = document.getElementById(PLATFORM_ANALYTICS_ID);
934
+ if (element === null) return null;
935
+ var value;
936
+ try {
937
+ var _element$textContent;
938
+ value = JSON.parse((_element$textContent = element.textContent) !== null && _element$textContent !== void 0 ? _element$textContent : "");
939
+ } catch (_unused) {
940
+ return null;
941
+ }
942
+ if (_typeof._typeof(value) !== "object" || value === null || !("enabled" in value) || value.enabled !== true) {
943
+ return null;
944
+ }
945
+ var contentVersion = "contentVersion" in value && typeof value.contentVersion === "string" ? value.contentVersion : undefined;
946
+ readFromPage = _typeof._objectSpread2({
947
+ enabled: true
948
+ }, contentVersion !== undefined ? {
949
+ contentVersion: contentVersion
950
+ } : {});
951
+ return readFromPage;
952
+ }
953
+
954
+ /** On the server, what the platform handed it; in the browser, what the server wrote. */
955
+ function analyticsOfThisPage() {
956
+ return typeof document === "undefined" ? analyticsFromPlatform() : analyticsFromPage();
957
+ }
958
+
959
+ /**
960
+ * The setting as JSON that can sit inside a `<script>`: a `<` is written as
961
+ * `\u003c`, so nothing in it can end the element.
962
+ */
963
+ function embeddableJson(value) {
964
+ return JSON.stringify(value).replace(/</g, "\\u003c");
965
+ }
966
+
967
+ /**
968
+ * Where the server render leaves the setting for the browser. Rendered the
969
+ * same on both sides -- the browser renders what it read -- so it hydrates
970
+ * without a mismatch.
882
971
  */
972
+ function PlatformAnalytics(_ref) {
973
+ var value = _ref.value;
974
+ return /*#__PURE__*/jsxRuntime.jsx("script", {
975
+ type: "application/json",
976
+ id: PLATFORM_ANALYTICS_ID,
977
+ dangerouslySetInnerHTML: {
978
+ __html: embeddableJson(value)
979
+ }
980
+ });
981
+ }
982
+
883
983
  var REFRESH_INTERVAL_MS = 500;
884
984
 
885
985
  /**
@@ -951,7 +1051,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
951
1051
  */
952
1052
  var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
953
1053
  var ValTanStackProvider = function ValTanStackProvider(props) {
954
- var _props$draft, _props$analytics, _draftModeReady$curre2;
1054
+ var _props$draft, _draftModeReady$curre2;
955
1055
  // TODO: use config:
956
1056
  var route = "/api/val";
957
1057
  /**
@@ -1010,8 +1110,25 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1010
1110
  * As the page was rendered. A ref, not the prop, for the reason
1011
1111
  * `initialDraft` is one: a later render's prop is a client navigation's
1012
1112
  * loader, which reads nothing.
1113
+ *
1114
+ * A layout that passes nothing gets the project's setting from Val's
1115
+ * hosting itself (`platformAnalytics.tsx`): the server render reads what
1116
+ * the platform handed it and writes it into the page, and the browser
1117
+ * reads it back. So switching analytics on in the project's settings is
1118
+ * enough; the layout does not have to read it.
1013
1119
  */
1014
- var analyticsSetting = React__default["default"].useRef((_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : null).current;
1120
+ // Not in a demo: its `/api/val` is static files, with nowhere to count.
1121
+ var _React$useState = React__default["default"].useState(function () {
1122
+ return props.analytics === undefined && !props.demo ? analyticsOfThisPage() : null;
1123
+ }),
1124
+ _React$useState2 = _typeof._slicedToArray(_React$useState, 1),
1125
+ platformAnalytics = _React$useState2[0];
1126
+ var _React$useState3 = React__default["default"].useState(function () {
1127
+ var _props$analytics;
1128
+ return (_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : platformAnalytics;
1129
+ }),
1130
+ _React$useState4 = _typeof._slicedToArray(_React$useState3, 1),
1131
+ analyticsSetting = _React$useState4[0];
1015
1132
  var analytics = (analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.enabled) === true;
1016
1133
  var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
1017
1134
  var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
@@ -1049,10 +1166,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1049
1166
  // transition: React keeps the static content visible while hooks suspend
1050
1167
  // and then swaps to draft data as a normal update — no Suspense fallback
1051
1168
  // flash and no hydration mismatch.
1052
- var _React$useState = React__default["default"].useState(false),
1053
- _React$useState2 = _typeof._slicedToArray(_React$useState, 2),
1054
- suspendActive = _React$useState2[0],
1055
- setSuspendActive = _React$useState2[1];
1169
+ var _React$useState5 = React__default["default"].useState(false),
1170
+ _React$useState6 = _typeof._slicedToArray(_React$useState5, 2),
1171
+ suspendActive = _React$useState6[0],
1172
+ setSuspendActive = _React$useState6[1];
1056
1173
  /**
1057
1174
  * Whether the studio has said it sent everything it holds.
1058
1175
  *
@@ -1063,14 +1180,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1063
1180
  */
1064
1181
  // A server-read draft is everything there is: a module missing from it has
1065
1182
  // no changes, so there is nothing more to wait for.
1066
- var _React$useState3 = React__default["default"].useState(hasDraft),
1067
- _React$useState4 = _typeof._slicedToArray(_React$useState3, 2),
1068
- draftSourcesSynced = _React$useState4[0],
1069
- setDraftSourcesSynced = _React$useState4[1];
1070
- var _React$useState5 = React__default["default"].useState(),
1071
- _React$useState6 = _typeof._slicedToArray(_React$useState5, 2),
1072
- mountOverlay = _React$useState6[0],
1073
- setMountOverlay = _React$useState6[1];
1183
+ var _React$useState7 = React__default["default"].useState(hasDraft),
1184
+ _React$useState8 = _typeof._slicedToArray(_React$useState7, 2),
1185
+ draftSourcesSynced = _React$useState8[0],
1186
+ setDraftSourcesSynced = _React$useState8[1];
1187
+ var _React$useState9 = React__default["default"].useState(),
1188
+ _React$useState0 = _typeof._slicedToArray(_React$useState9, 2),
1189
+ mountOverlay = _React$useState0[0],
1190
+ setMountOverlay = _React$useState0[1];
1074
1191
  /**
1075
1192
  * Whether this document is the studio's canvas frame.
1076
1193
  *
@@ -1084,16 +1201,16 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1084
1201
  * Read once, in the same effect as `mountOverlay`: it is a property of how
1085
1202
  * the document was loaded, and it cannot change without a navigation.
1086
1203
  */
1087
- var _React$useState7 = React__default["default"].useState(false),
1088
- _React$useState8 = _typeof._slicedToArray(_React$useState7, 2),
1089
- isCanvas = _React$useState8[0],
1090
- setIsCanvas = _React$useState8[1];
1204
+ var _React$useState1 = React__default["default"].useState(false),
1205
+ _React$useState10 = _typeof._slicedToArray(_React$useState1, 2),
1206
+ isCanvas = _React$useState10[0],
1207
+ setIsCanvas = _React$useState10[1];
1091
1208
  // Known on the server when it read a draft: `fetchValDraft` only reads one
1092
1209
  // in draft mode. Otherwise unknown until `/draft/stat` answers.
1093
- var _React$useState9 = React__default["default"].useState(hasDraft ? true : null),
1094
- _React$useState0 = _typeof._slicedToArray(_React$useState9, 2),
1095
- draftMode = _React$useState0[0],
1096
- setDraftMode = _React$useState0[1];
1210
+ var _React$useState11 = React__default["default"].useState(hasDraft ? true : null),
1211
+ _React$useState12 = _typeof._slicedToArray(_React$useState11, 2),
1212
+ draftMode = _React$useState12[0],
1213
+ setDraftMode = _React$useState12[1];
1097
1214
  /**
1098
1215
  * Resolves when `draftMode` stops being unknown.
1099
1216
  *
@@ -1128,10 +1245,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1128
1245
  (_draftModeReady$curre = draftModeReady.current) === null || _draftModeReady$curre === void 0 || _draftModeReady$curre.resolve();
1129
1246
  }
1130
1247
  }, [draftMode]);
1131
- var _React$useState1 = React__default["default"].useState(false),
1132
- _React$useState10 = _typeof._slicedToArray(_React$useState1, 2),
1133
- spaReady = _React$useState10[0],
1134
- setSpaReady = _React$useState10[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
1248
+ var _React$useState13 = React__default["default"].useState(false),
1249
+ _React$useState14 = _typeof._slicedToArray(_React$useState13, 2),
1250
+ spaReady = _React$useState14[0],
1251
+ setSpaReady = _React$useState14[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
1135
1252
  var router = reactRouter.useRouter();
1136
1253
  var _React$useTransition = React__default["default"].useTransition(),
1137
1254
  _React$useTransition2 = _typeof._slicedToArray(_React$useTransition, 2),
@@ -1147,10 +1264,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1147
1264
  */
1148
1265
  var isRefreshingRef = React__default["default"].useRef(false);
1149
1266
  var rerenderCounterRef = React__default["default"].useRef(0);
1150
- var _React$useState11 = React__default["default"].useState(null),
1151
- _React$useState12 = _typeof._slicedToArray(_React$useState11, 2),
1152
- iframeSrc = _React$useState12[0],
1153
- setIframeSrc = _React$useState12[1];
1267
+ var _React$useState15 = React__default["default"].useState(null),
1268
+ _React$useState16 = _typeof._slicedToArray(_React$useState15, 2),
1269
+ iframeSrc = _React$useState16[0],
1270
+ setIframeSrc = _React$useState16[1];
1154
1271
  var pathname = reactRouter.useRouterState({
1155
1272
  select: function select(state) {
1156
1273
  return state.location.pathname;
@@ -1595,10 +1712,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1595
1712
  window.dispatchEvent(new CustomEvent("val-append-overlay"));
1596
1713
  }
1597
1714
  });
1598
- var _React$useState13 = React__default["default"].useState(null),
1599
- _React$useState14 = _typeof._slicedToArray(_React$useState13, 2),
1600
- dropZone = _React$useState14[0],
1601
- setDropZone = _React$useState14[1];
1715
+ var _React$useState17 = React__default["default"].useState(null),
1716
+ _React$useState18 = _typeof._slicedToArray(_React$useState17, 2),
1717
+ dropZone = _React$useState18[0],
1718
+ setDropZone = _React$useState18[1];
1602
1719
  React__default["default"].useEffect(function () {
1603
1720
  var storedDropZone = localStorage.getItem("val-menu-drop-zone-default");
1604
1721
  if (storedDropZone) {
@@ -1611,10 +1728,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1611
1728
  var initTheme = React__default["default"].useMemo(function () {
1612
1729
  return initSessionTheme(props.config);
1613
1730
  }, [props.config]);
1614
- var _React$useState15 = React__default["default"].useState(false),
1615
- _React$useState16 = _typeof._slicedToArray(_React$useState15, 2),
1616
- spaLoaded = _React$useState16[0],
1617
- setSpaLoaded = _React$useState16[1];
1731
+ var _React$useState19 = React__default["default"].useState(false),
1732
+ _React$useState20 = _typeof._slicedToArray(_React$useState19, 2),
1733
+ spaLoaded = _React$useState20[0],
1734
+ setSpaLoaded = _React$useState20[1];
1618
1735
  React__default["default"].useEffect(function () {
1619
1736
  var listener = function listener() {
1620
1737
  setSpaLoaded(true);
@@ -1662,7 +1779,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1662
1779
  snapshot: snapshot,
1663
1780
  suspend: suspendActive,
1664
1781
  store: valStore,
1665
- children: [props.children, dropZone !== null && !spaLoaded && mountOverlay &&
1782
+ children: [props.children, platformAnalytics !== null && /*#__PURE__*/jsxRuntime.jsx(PlatformAnalytics, {
1783
+ value: platformAnalytics
1784
+ }), dropZone !== null && !spaLoaded && mountOverlay &&
1666
1785
  // The canvas frame loads no SPA, so its pill would spin for ever.
1667
1786
  !isCanvas && initTheme !== null && /*#__PURE__*/jsxRuntime.jsxs(React__default["default"].Fragment, {
1668
1787
  children: [/*#__PURE__*/jsxRuntime.jsx("style", {
@@ -5,7 +5,7 @@ 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, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX } from '@valbuild/react/stega';
8
- import { r as readValEnableCookie, _ as _toConsumableArray, V as VERSION$1 } from './version-ac1d27a3.esm.js';
8
+ import { r as readValEnableCookie, _ as _toConsumableArray, V as VERSION$1 } from './version-f383f1ce.esm.js';
9
9
  export { ValRichText } from '@valbuild/react/internal';
10
10
  import { VERSION, VAL_APP_PATH, VAL_OVERLAY_ID, VAL_APP_ID } from '@valbuild/ui';
11
11
  import { useRouter, useRouterState } from '@tanstack/react-router';
@@ -847,15 +847,115 @@ function shouldSafetyRefresh(state) {
847
847
  }
848
848
 
849
849
  /**
850
- * Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
850
+ * Content analytics as Val's hosting sets it, for a site whose layout passes
851
+ * `<ValProvider>` no `analytics` of its own.
852
+ *
853
+ * Switching analytics on in a hosted project's settings sets the project's
854
+ * `VAL_ANALYTICS` secret, and the platform starts the site's isolates again
855
+ * with it -- along with `VAL_CONTENT_VERSION`, the id of the content version
856
+ * they serve. Both arrive in `globalThis.__PLATFORM_SECRETS`. Reading them
857
+ * here, rather than only in the layout's loader (`fetchValAnalytics()`), is
858
+ * what makes the switch enough on its own: a site needs no code for it.
859
+ *
860
+ * The server render reads them and writes what it read into the page, as a
861
+ * few bytes of JSON; the browser reads that back. Nothing is written while
862
+ * analytics is off, so the page is the same as without Val's hosting.
863
+ *
864
+ * Only what the platform HANDED this isolate is read, never `process.env`:
865
+ * that is baked into the bundle at build time, and a `VAL_ANALYTICS` there
866
+ * would be a second switch, in the code, that keeps counting after the owner
867
+ * has turned it off.
868
+ */
869
+
870
+ /** The element the server render writes the setting into. */
871
+ var PLATFORM_ANALYTICS_ID = "__val_analytics";
872
+
873
+ /**
874
+ * One secret the platform handed this isolate, when it is one of Val's.
875
+ * Read off the object as it is, the way the generated `fetchValAnalytics()`
876
+ * does, so the two cannot disagree about what was handed over.
851
877
  */
878
+ function platformSecret(name) {
879
+ var handed = Reflect.get(globalThis, "__PLATFORM_SECRETS");
880
+ return _typeof(handed) === "object" && handed !== null ? Reflect.get(handed, name) : undefined;
881
+ }
882
+
883
+ /** The setting the platform handed this isolate; null when it is not on. */
884
+ function analyticsFromPlatform() {
885
+ if (platformSecret("VAL_ANALYTICS") !== "true") return null;
886
+ var contentVersion = platformSecret("VAL_CONTENT_VERSION");
887
+ return _objectSpread2({
888
+ enabled: true
889
+ }, typeof contentVersion === "string" && contentVersion !== "" ? {
890
+ contentVersion: contentVersion
891
+ } : {});
892
+ }
893
+
852
894
  /**
853
- * The floor between server re-renders.
895
+ * What the page said, once it said it. The element lives inside the provider,
896
+ * so a client navigation that unmounts the provider takes it with it, and the
897
+ * provider mounted again must still know: the page did not stop being one
898
+ * with analytics on. A page load starts this module again.
854
899
  *
855
- * `router.invalidate()` re-runs every loader of the current match tree — there
856
- * is no per-module invalidation — so this is about not queueing a round trip
857
- * per keystroke, not about batching for its own sake.
900
+ * It is the page's setting, so it reaches every provider on the page that is
901
+ * not told otherwise -- one that is passed `analytics`, on the server and in
902
+ * the browser, decides for itself.
903
+ */
904
+ var readFromPage = null;
905
+
906
+ /** The setting the server render wrote into this page; null when it wrote none. */
907
+ function analyticsFromPage() {
908
+ if (readFromPage !== null) return readFromPage;
909
+ var element = document.getElementById(PLATFORM_ANALYTICS_ID);
910
+ if (element === null) return null;
911
+ var value;
912
+ try {
913
+ var _element$textContent;
914
+ value = JSON.parse((_element$textContent = element.textContent) !== null && _element$textContent !== void 0 ? _element$textContent : "");
915
+ } catch (_unused) {
916
+ return null;
917
+ }
918
+ if (_typeof(value) !== "object" || value === null || !("enabled" in value) || value.enabled !== true) {
919
+ return null;
920
+ }
921
+ var contentVersion = "contentVersion" in value && typeof value.contentVersion === "string" ? value.contentVersion : undefined;
922
+ readFromPage = _objectSpread2({
923
+ enabled: true
924
+ }, contentVersion !== undefined ? {
925
+ contentVersion: contentVersion
926
+ } : {});
927
+ return readFromPage;
928
+ }
929
+
930
+ /** On the server, what the platform handed it; in the browser, what the server wrote. */
931
+ function analyticsOfThisPage() {
932
+ return typeof document === "undefined" ? analyticsFromPlatform() : analyticsFromPage();
933
+ }
934
+
935
+ /**
936
+ * The setting as JSON that can sit inside a `<script>`: a `<` is written as
937
+ * `\u003c`, so nothing in it can end the element.
938
+ */
939
+ function embeddableJson(value) {
940
+ return JSON.stringify(value).replace(/</g, "\\u003c");
941
+ }
942
+
943
+ /**
944
+ * Where the server render leaves the setting for the browser. Rendered the
945
+ * same on both sides -- the browser renders what it read -- so it hydrates
946
+ * without a mismatch.
858
947
  */
948
+ function PlatformAnalytics(_ref) {
949
+ var value = _ref.value;
950
+ return /*#__PURE__*/jsx("script", {
951
+ type: "application/json",
952
+ id: PLATFORM_ANALYTICS_ID,
953
+ dangerouslySetInnerHTML: {
954
+ __html: embeddableJson(value)
955
+ }
956
+ });
957
+ }
958
+
859
959
  var REFRESH_INTERVAL_MS = 500;
860
960
 
861
961
  /**
@@ -927,7 +1027,7 @@ var DRAFT_HANDSHAKE_POLL_MS = 100;
927
1027
  */
928
1028
  var DRAFT_HANDSHAKE_TIMEOUT_MS = 10000;
929
1029
  var ValTanStackProvider = function ValTanStackProvider(props) {
930
- var _props$draft, _props$analytics, _draftModeReady$curre2;
1030
+ var _props$draft, _draftModeReady$curre2;
931
1031
  // TODO: use config:
932
1032
  var route = "/api/val";
933
1033
  /**
@@ -986,8 +1086,25 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
986
1086
  * As the page was rendered. A ref, not the prop, for the reason
987
1087
  * `initialDraft` is one: a later render's prop is a client navigation's
988
1088
  * loader, which reads nothing.
1089
+ *
1090
+ * A layout that passes nothing gets the project's setting from Val's
1091
+ * hosting itself (`platformAnalytics.tsx`): the server render reads what
1092
+ * the platform handed it and writes it into the page, and the browser
1093
+ * reads it back. So switching analytics on in the project's settings is
1094
+ * enough; the layout does not have to read it.
989
1095
  */
990
- var analyticsSetting = React.useRef((_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : null).current;
1096
+ // Not in a demo: its `/api/val` is static files, with nowhere to count.
1097
+ var _React$useState = React.useState(function () {
1098
+ return props.analytics === undefined && !props.demo ? analyticsOfThisPage() : null;
1099
+ }),
1100
+ _React$useState2 = _slicedToArray(_React$useState, 1),
1101
+ platformAnalytics = _React$useState2[0];
1102
+ var _React$useState3 = React.useState(function () {
1103
+ var _props$analytics;
1104
+ return (_props$analytics = props.analytics) !== null && _props$analytics !== void 0 ? _props$analytics : platformAnalytics;
1105
+ }),
1106
+ _React$useState4 = _slicedToArray(_React$useState3, 1),
1107
+ analyticsSetting = _React$useState4[0];
991
1108
  var analytics = (analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.enabled) === true;
992
1109
  var contentVersion = analyticsSetting === null || analyticsSetting === void 0 ? void 0 : analyticsSetting.contentVersion;
993
1110
  var snapshot = initialDraft === null || initialDraft === void 0 ? void 0 : initialDraft.snapshot;
@@ -1025,10 +1142,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1025
1142
  // transition: React keeps the static content visible while hooks suspend
1026
1143
  // and then swaps to draft data as a normal update — no Suspense fallback
1027
1144
  // flash and no hydration mismatch.
1028
- var _React$useState = React.useState(false),
1029
- _React$useState2 = _slicedToArray(_React$useState, 2),
1030
- suspendActive = _React$useState2[0],
1031
- setSuspendActive = _React$useState2[1];
1145
+ var _React$useState5 = React.useState(false),
1146
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
1147
+ suspendActive = _React$useState6[0],
1148
+ setSuspendActive = _React$useState6[1];
1032
1149
  /**
1033
1150
  * Whether the studio has said it sent everything it holds.
1034
1151
  *
@@ -1039,14 +1156,14 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1039
1156
  */
1040
1157
  // A server-read draft is everything there is: a module missing from it has
1041
1158
  // no changes, so there is nothing more to wait for.
1042
- var _React$useState3 = React.useState(hasDraft),
1043
- _React$useState4 = _slicedToArray(_React$useState3, 2),
1044
- draftSourcesSynced = _React$useState4[0],
1045
- setDraftSourcesSynced = _React$useState4[1];
1046
- var _React$useState5 = React.useState(),
1047
- _React$useState6 = _slicedToArray(_React$useState5, 2),
1048
- mountOverlay = _React$useState6[0],
1049
- setMountOverlay = _React$useState6[1];
1159
+ var _React$useState7 = React.useState(hasDraft),
1160
+ _React$useState8 = _slicedToArray(_React$useState7, 2),
1161
+ draftSourcesSynced = _React$useState8[0],
1162
+ setDraftSourcesSynced = _React$useState8[1];
1163
+ var _React$useState9 = React.useState(),
1164
+ _React$useState0 = _slicedToArray(_React$useState9, 2),
1165
+ mountOverlay = _React$useState0[0],
1166
+ setMountOverlay = _React$useState0[1];
1050
1167
  /**
1051
1168
  * Whether this document is the studio's canvas frame.
1052
1169
  *
@@ -1060,16 +1177,16 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1060
1177
  * Read once, in the same effect as `mountOverlay`: it is a property of how
1061
1178
  * the document was loaded, and it cannot change without a navigation.
1062
1179
  */
1063
- var _React$useState7 = React.useState(false),
1064
- _React$useState8 = _slicedToArray(_React$useState7, 2),
1065
- isCanvas = _React$useState8[0],
1066
- setIsCanvas = _React$useState8[1];
1180
+ var _React$useState1 = React.useState(false),
1181
+ _React$useState10 = _slicedToArray(_React$useState1, 2),
1182
+ isCanvas = _React$useState10[0],
1183
+ setIsCanvas = _React$useState10[1];
1067
1184
  // Known on the server when it read a draft: `fetchValDraft` only reads one
1068
1185
  // in draft mode. Otherwise unknown until `/draft/stat` answers.
1069
- var _React$useState9 = React.useState(hasDraft ? true : null),
1070
- _React$useState0 = _slicedToArray(_React$useState9, 2),
1071
- draftMode = _React$useState0[0],
1072
- setDraftMode = _React$useState0[1];
1186
+ var _React$useState11 = React.useState(hasDraft ? true : null),
1187
+ _React$useState12 = _slicedToArray(_React$useState11, 2),
1188
+ draftMode = _React$useState12[0],
1189
+ setDraftMode = _React$useState12[1];
1073
1190
  /**
1074
1191
  * Resolves when `draftMode` stops being unknown.
1075
1192
  *
@@ -1104,10 +1221,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1104
1221
  (_draftModeReady$curre = draftModeReady.current) === null || _draftModeReady$curre === void 0 || _draftModeReady$curre.resolve();
1105
1222
  }
1106
1223
  }, [draftMode]);
1107
- var _React$useState1 = React.useState(false),
1108
- _React$useState10 = _slicedToArray(_React$useState1, 2),
1109
- spaReady = _React$useState10[0],
1110
- setSpaReady = _React$useState10[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
1224
+ var _React$useState13 = React.useState(false),
1225
+ _React$useState14 = _slicedToArray(_React$useState13, 2),
1226
+ spaReady = _React$useState14[0],
1227
+ setSpaReady = _React$useState14[1]; // TODO: consider removing spaReady - it is not used? If we remove, clean up the custom events that send the message too...
1111
1228
  var router = useRouter();
1112
1229
  var _React$useTransition = React.useTransition(),
1113
1230
  _React$useTransition2 = _slicedToArray(_React$useTransition, 2),
@@ -1123,10 +1240,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1123
1240
  */
1124
1241
  var isRefreshingRef = React.useRef(false);
1125
1242
  var rerenderCounterRef = React.useRef(0);
1126
- var _React$useState11 = React.useState(null),
1127
- _React$useState12 = _slicedToArray(_React$useState11, 2),
1128
- iframeSrc = _React$useState12[0],
1129
- setIframeSrc = _React$useState12[1];
1243
+ var _React$useState15 = React.useState(null),
1244
+ _React$useState16 = _slicedToArray(_React$useState15, 2),
1245
+ iframeSrc = _React$useState16[0],
1246
+ setIframeSrc = _React$useState16[1];
1130
1247
  var pathname = useRouterState({
1131
1248
  select: function select(state) {
1132
1249
  return state.location.pathname;
@@ -1571,10 +1688,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1571
1688
  window.dispatchEvent(new CustomEvent("val-append-overlay"));
1572
1689
  }
1573
1690
  });
1574
- var _React$useState13 = React.useState(null),
1575
- _React$useState14 = _slicedToArray(_React$useState13, 2),
1576
- dropZone = _React$useState14[0],
1577
- setDropZone = _React$useState14[1];
1691
+ var _React$useState17 = React.useState(null),
1692
+ _React$useState18 = _slicedToArray(_React$useState17, 2),
1693
+ dropZone = _React$useState18[0],
1694
+ setDropZone = _React$useState18[1];
1578
1695
  React.useEffect(function () {
1579
1696
  var storedDropZone = localStorage.getItem("val-menu-drop-zone-default");
1580
1697
  if (storedDropZone) {
@@ -1587,10 +1704,10 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1587
1704
  var initTheme = React.useMemo(function () {
1588
1705
  return initSessionTheme(props.config);
1589
1706
  }, [props.config]);
1590
- var _React$useState15 = React.useState(false),
1591
- _React$useState16 = _slicedToArray(_React$useState15, 2),
1592
- spaLoaded = _React$useState16[0],
1593
- setSpaLoaded = _React$useState16[1];
1707
+ var _React$useState19 = React.useState(false),
1708
+ _React$useState20 = _slicedToArray(_React$useState19, 2),
1709
+ spaLoaded = _React$useState20[0],
1710
+ setSpaLoaded = _React$useState20[1];
1594
1711
  React.useEffect(function () {
1595
1712
  var listener = function listener() {
1596
1713
  setSpaLoaded(true);
@@ -1638,7 +1755,9 @@ var ValTanStackProvider = function ValTanStackProvider(props) {
1638
1755
  snapshot: snapshot,
1639
1756
  suspend: suspendActive,
1640
1757
  store: valStore,
1641
- children: [props.children, dropZone !== null && !spaLoaded && mountOverlay &&
1758
+ children: [props.children, platformAnalytics !== null && /*#__PURE__*/jsx(PlatformAnalytics, {
1759
+ value: platformAnalytics
1760
+ }), dropZone !== null && !spaLoaded && mountOverlay &&
1642
1761
  // The canvas frame loads no SPA, so its pill would spin for ever.
1643
1762
  !isCanvas && initTheme !== null && /*#__PURE__*/jsxs(React.Fragment, {
1644
1763
  children: [/*#__PURE__*/jsx("style", {
@@ -95,7 +95,7 @@ var packageJson = {
95
95
  "tanstack-router",
96
96
  "react"
97
97
  ],
98
- version: "0.149.0",
98
+ version: "0.149.1",
99
99
  scripts: {
100
100
  typecheck: "tsc --noEmit",
101
101
  test: "jest"
@@ -95,7 +95,7 @@ var packageJson = {
95
95
  "tanstack-router",
96
96
  "react"
97
97
  ],
98
- version: "0.149.0",
98
+ version: "0.149.1",
99
99
  scripts: {
100
100
  typecheck: "tsc --noEmit",
101
101
  test: "jest"
@@ -93,7 +93,7 @@ var packageJson = {
93
93
  "tanstack-router",
94
94
  "react"
95
95
  ],
96
- version: "0.149.0",
96
+ version: "0.149.1",
97
97
  scripts: {
98
98
  typecheck: "tsc --noEmit",
99
99
  test: "jest"
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "tanstack-router",
15
15
  "react"
16
16
  ],
17
- "version": "0.149.0",
17
+ "version": "0.149.1",
18
18
  "main": "dist/valbuild-tanstack.cjs.js",
19
19
  "module": "dist/valbuild-tanstack.esm.js",
20
20
  "exports": {
@@ -48,12 +48,12 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@valbuild/core": "0.148.7",
51
- "@valbuild/language-server": "0.149.0",
52
- "@valbuild/mcp": "0.149.0",
53
- "@valbuild/react": "0.149.0",
54
- "@valbuild/server": "0.149.0",
51
+ "@valbuild/language-server": "0.149.1",
52
+ "@valbuild/mcp": "0.149.1",
53
+ "@valbuild/react": "0.149.1",
54
+ "@valbuild/server": "0.149.1",
55
55
  "@valbuild/shared": "0.148.7",
56
- "@valbuild/ui": "0.149.0"
56
+ "@valbuild/ui": "0.149.1"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@tanstack/react-router": "^1.170.41",
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('../../dist/version-3ad556b9.cjs.dev.js');
5
+ var version = require('../../dist/version-f09c0421.cjs.dev.js');
6
6
  var asyncToGenerator = require('../../dist/asyncToGenerator-c3823d62.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var _typeof = require('../../dist/typeof-dd0246a1.cjs.dev.js');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('../../dist/version-63cad8df.cjs.prod.js');
5
+ var version = require('../../dist/version-68b769fa.cjs.prod.js');
6
6
  var asyncToGenerator = require('../../dist/asyncToGenerator-8e5c36c8.cjs.prod.js');
7
7
  var core = require('@valbuild/core');
8
8
  var _typeof = require('../../dist/typeof-8998e126.cjs.prod.js');
@@ -1,4 +1,4 @@
1
- import { V as VERSION, _ as _toConsumableArray, s as setValEnableCookieReader } from '../../dist/version-ac1d27a3.esm.js';
1
+ import { V as VERSION, _ as _toConsumableArray, s as setValEnableCookieReader } from '../../dist/version-f383f1ce.esm.js';
2
2
  import { _ as _asyncToGenerator, a as _regenerator } from '../../dist/asyncToGenerator-500f022f.esm.js';
3
3
  import { Internal } from '@valbuild/core';
4
4
  import { _ as _objectSpread2, a as _slicedToArray, b as _createForOfIteratorHelper, g as _defineProperty, c as _typeof } from '../../dist/typeof-66e2d869.esm.js';