@valbuild/react 0.152.2 → 0.153.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,32 @@
1
1
  # @valbuild/react
2
2
 
3
+ ## 0.153.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1031](https://github.com/valbuild/val/pull/1031) [`6ec1a5d`](https://github.com/valbuild/val/commit/6ec1a5d244f0d6e064eca4135f167dfa79744f9a) Thanks [@freekh](https://github.com/freekh)! - A page no longer shows content made for code it does not have yet. When the Studio is ahead of the page (it picked up a code change first, or the browser is still running the previous build), the page keeps showing its own content for the modules whose schema changed, and says "The code changed" with a **Reload** button — in the overlay on your site, and above the page in the Studio. In local development the page usually catches up a moment later by itself, and the notice goes away without a reload.
8
+ - Updated dependencies [[`6ec1a5d`](https://github.com/valbuild/val/commit/6ec1a5d244f0d6e064eca4135f167dfa79744f9a), [`f1048d9`](https://github.com/valbuild/val/commit/f1048d93a76138d031b30d059c444a8f754b484d), [`b14870b`](https://github.com/valbuild/val/commit/b14870bebdc128234bb16e4ea06a0151d18c4771)]:
9
+ - @valbuild/shared@0.153.1
10
+ - @valbuild/ui@0.153.1
11
+
12
+ ## 0.153.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#1016](https://github.com/valbuild/val/pull/1016) [`2e70d13`](https://github.com/valbuild/val/commit/2e70d13cf7ca25874900c9ea25227df2876727b9) Thanks [@freekh](https://github.com/freekh)! - Removed what 0.151.0 kept only so that a Studio, a page and a server from the release before could still talk to each other during a deploy:
17
+
18
+ - **`PUT /api/val/sources/~`** is gone. Nothing in 0.151.0 asked it: the Studio reads modules through `GET /api/val/manifest` and `GET /api/val/modules/~<path>`, and `fetchVal`, `useVal` and the MCP tools read the server's content in-process. If a script or test of yours read content through it, read one module with `GET /api/val/modules/~<path>` instead. Its answer has the module's `source` and `version`, and an `entries` map holding the `.jsonValues()` entries pending changes touched.
19
+ - **`ValDraft.base`** is gone from the type. It has not been sent or read since 0.151.0, so a `draft` you pass to `ValProvider` is not affected.
20
+ - **A page no longer accepts edits relayed by a Studio from before 0.151.0.** Such a Studio sent each module as a bare `source`. After the upgrade, the Studio and your pages come from the same deploy, so this only matters while an older Studio is still open in a tab during a rollout. Reloading that tab fixes it.
21
+ - **`/api/val/stat`** no longer needs `sourcesSha` and `schemaSha`. The Studio now tells your local server which version it last saw, and the server still sends both fields for a Studio of 0.151.0. They stop being sent in the next release.
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`67145fd`](https://github.com/valbuild/val/commit/67145fd16e35f2e3e0988ca5690fe5a4f84c1a41), [`67145fd`](https://github.com/valbuild/val/commit/67145fd16e35f2e3e0988ca5690fe5a4f84c1a41), [`efa1f7d`](https://github.com/valbuild/val/commit/efa1f7d810f3c4e4e21502c9cc81ce86da93650c), [`efa1f7d`](https://github.com/valbuild/val/commit/efa1f7d810f3c4e4e21502c9cc81ce86da93650c), [`27e51ba`](https://github.com/valbuild/val/commit/27e51baadce61b2cbee2d5ef227aae045ccb2e21), [`efa1f7d`](https://github.com/valbuild/val/commit/efa1f7d810f3c4e4e21502c9cc81ce86da93650c), [`2e70d13`](https://github.com/valbuild/val/commit/2e70d13cf7ca25874900c9ea25227df2876727b9), [`2e70d13`](https://github.com/valbuild/val/commit/2e70d13cf7ca25874900c9ea25227df2876727b9), [`2e70d13`](https://github.com/valbuild/val/commit/2e70d13cf7ca25874900c9ea25227df2876727b9), [`efa1f7d`](https://github.com/valbuild/val/commit/efa1f7d810f3c4e4e21502c9cc81ce86da93650c), [`2e70d13`](https://github.com/valbuild/val/commit/2e70d13cf7ca25874900c9ea25227df2876727b9), [`67145fd`](https://github.com/valbuild/val/commit/67145fd16e35f2e3e0988ca5690fe5a4f84c1a41), [`efa1f7d`](https://github.com/valbuild/val/commit/efa1f7d810f3c4e4e21502c9cc81ce86da93650c), [`efa1f7d`](https://github.com/valbuild/val/commit/efa1f7d810f3c4e4e21502c9cc81ce86da93650c), [`56ab7d5`](https://github.com/valbuild/val/commit/56ab7d5818772a9e310a561ebdb798b27ee704c9)]:
26
+ - @valbuild/ui@0.153.0
27
+ - @valbuild/core@0.153.0
28
+ - @valbuild/shared@0.153.0
29
+
3
30
  ## 0.152.2
4
31
 
5
32
  ### Patch Changes
@@ -0,0 +1,29 @@
1
+ import type { ModuleFilePath } from "@valbuild/core";
2
+ import type { SchemaRule } from "./layered.js";
3
+ /**
4
+ * What a page's hooks are told by the schema rule, kept as the set of
5
+ * modules whose relayed content this page could not read, and announced each
6
+ * time that set changes (`announce`).
7
+ *
8
+ * The rule runs while a component renders, so nothing is announced then: the
9
+ * set is compared and announced once the render is over, in one microtask
10
+ * for every module a render read. A module the page reads with its own
11
+ * schema again -- its code caught up, which in local development is usually
12
+ * a hot reload a moment after the Studio's -- leaves the set, so the notice
13
+ * goes away by itself instead of asking for a reload nothing needs.
14
+ */
15
+ export type CodeChangedReporter = {
16
+ /** For the hooks' env (`SchemaRule.schemaChecked`). */
17
+ schemaChecked: NonNullable<SchemaRule["schemaChecked"]>;
18
+ /**
19
+ * The modules refused now, as last announced: for whatever starts
20
+ * listening after the announcement (the overlay once it has loaded, the
21
+ * canvas bridge once it has mounted).
22
+ */
23
+ modules(): ModuleFilePath[];
24
+ };
25
+ export declare function codeChangedReporter(announce: (modules: ModuleFilePath[]) => void): CodeChangedReporter;
26
+ /** The `val-overlay-spa` event that says {@link CodeChangedReporter.modules}. */
27
+ export declare function dispatchCodeChanged(modules: ModuleFilePath[]): void;
28
+ /** {@link codeChangedReporter} announcing to this window's Val overlay. */
29
+ export declare function windowCodeChangedReporter(): CodeChangedReporter;
@@ -45,13 +45,6 @@ export type ValDraft = {
45
45
  * looking at the proposal too. A draft, when there is one, applies on top.
46
46
  */
47
47
  snapshot?: Record<ModuleFilePath, Json>;
48
- /**
49
- * @deprecated Not sent any more, and not read: the Studio's overlay reads
50
- * the base the server is on by version (the manifest names it), so a page
51
- * no longer hands it over. Kept on the type for a release, so a draft of
52
- * the release before still type-checks; it goes after that.
53
- */
54
- base?: Record<ModuleFilePath, Json>;
55
48
  /**
56
49
  * `false` when no draft was read -- draft mode is off -- and this carries
57
50
  * only the {@link snapshot}. Absent: a draft, as it always was.
@@ -2,6 +2,7 @@ export { ValExternalStore, applyValEvent, type HeldRead, type ValEventOutcome, }
2
2
  export { createDraftStore, draftHolds, draftHoldsVersions, isDraft, type ValDraft, } from "./draft.js";
3
3
  export { startRefreshLoop, type RefreshLoop } from "./refreshLoop.js";
4
4
  export { bundleSource, entryOfModuleSource, overlaySource, snapshotSource, type OverlayState, } from "./sources.js";
5
+ export { codeChangedReporter, dispatchCodeChanged, windowCodeChangedReporter, type CodeChangedReporter, } from "./codeChanged.js";
5
6
  export { layered, type LocatedRead, type SchemaRule, type LayeredView, } from "./layered.js";
6
7
  export { mapResolution, planOf, readWork, resolveModuleEntry, resolveVal, resolveValEntry, type ReadEnv, type ReadOf, type ReadPlan, type Resolution, type ResolveOptions, } from "./resolveVal.js";
7
8
  export { awaitResolved, fetchValFrom, readsOfFetchVal, useResolved, useResolvedEntry, useResolvedVal, type FetchValWithReads, type Ready, } from "./readers.js";
@@ -13,6 +13,18 @@ import type { ContentSource, EntryRead, ModuleRead } from "@valbuild/shared/inte
13
13
  export type SchemaRule = {
14
14
  schemaOf(path: ModuleFilePath): string | null;
15
15
  codeChanged?(path: ModuleFilePath, schema: string): Promise<void>;
16
+ /**
17
+ * Told what the rule decided about each answer that carries a version:
18
+ * `other` when it was passed over for its schema (there is no
19
+ * `codeChanged` to wait on) -- the content is made for code this reader
20
+ * does not run -- and `null` when its schema is this code's. A page says
21
+ * the first to the editor, with a reload, and takes it back on the second
22
+ * (`codeChangedReporter`).
23
+ */
24
+ schemaChecked?(path: ModuleFilePath, other: {
25
+ schema: string;
26
+ from: string;
27
+ } | null): void;
16
28
  };
17
29
  /** A module read, with the place in the list of the source that answered it. */
18
30
  export type LocatedRead = {
@@ -86,14 +86,6 @@ export type ValEventOutcome = {
86
86
  | {
87
87
  type: "updated";
88
88
  changed: boolean;
89
- /**
90
- * Sent by a Studio of the release before: a bare `source`, from a
91
- * Studio that never says `confirmed` -- so the page refreshes on the
92
- * change itself (`RefreshLoop.changedByPreviousStudio`), as that
93
- * release's page did. Goes with the relay's `source` (see
94
- * "Release-delayed deletions" in `docs/plans/one-content-model.md`).
95
- */
96
- fromPreviousStudio?: true;
97
89
  } | {
98
90
  type: "invalid";
99
91
  detail: unknown;
@@ -103,9 +95,7 @@ export type ValEventOutcome = {
103
95
  * `sources-synced` says the editor has sent everything it holds;
104
96
  * `confirmed` how far the server holds the editor's changes; a
105
97
  * `source-update` hands over one module's read, which the store keeps as it
106
- * is (`read`). A Studio from the release before sent the bare `source`
107
- * instead, and a page newer than the Studio it is open in -- a deploy rolling
108
- * out -- still takes that.
98
+ * is (`read`).
109
99
  *
110
100
  * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
111
101
  * provider had the same rule written inline.
@@ -25,22 +25,10 @@
25
25
  * moved what it holds (`changed`): its server render is older than what the
26
26
  * Studio has. A page rendered from the draft the Studio holds -- the
27
27
  * `draft` prop, read for this request -- is not refreshed for loading.
28
- * - **A Studio of the release before never says `confirmed`** (a deploy
29
- * rolling out: this page, that Studio). Its changes refresh the page as
30
- * they arrive (`changedByPreviousStudio`), as that release's page did,
31
- * until a `confirmed` says the Studio is this release's. They race the
32
- * write, as they did then; it lasts as long as the rollout.
33
28
  */
34
29
  export type RefreshLoop = {
35
30
  /** A relayed module moved what the page's store holds. */
36
31
  changed(): void;
37
- /**
38
- * A relayed module moved what the page's store holds, sent by a Studio of
39
- * the release before (a bare `source`), which never says `confirmed`: a
40
- * refresh, unless a `confirmed` has been told on this page. Goes with the
41
- * relay's `source` ("Release-delayed deletions").
42
- */
43
- changedByPreviousStudio(): void;
44
32
  /** The server holds the editor's changes up to `seq` (`null`: unknown). */
45
33
  confirmed(seq: number | null): void;
46
34
  /**
@@ -20,6 +20,7 @@ export type ReadEnv = {
20
20
  */
21
21
  readonly schemaVersionOf?: (module: ValModule<SelectorSource>) => string | null;
22
22
  readonly codeChanged?: SchemaRule["codeChanged"];
23
+ readonly schemaChecked?: SchemaRule["schemaChecked"];
23
24
  };
24
25
  /** Which source a module was read from, and the version of what it read. */
25
26
  export type ReadOf = {
@@ -6,6 +6,7 @@ import { _ as _typeof } from '../../dist/typeof-9915e135.browser.esm.js';
6
6
  import { Internal, RecordSchema } from '@valbuild/core';
7
7
  import { deepEqual } from '@valbuild/core/patch';
8
8
  import { _ as _slicedToArray } from '../../dist/slicedToArray-b66ff800.browser.esm.js';
9
+ import { CODE_CHANGED_EVENT } from '@valbuild/shared/internal';
9
10
  import '@vercel/stega';
10
11
 
11
12
  function _objectWithoutPropertiesLoose(r, e) {
@@ -485,9 +486,7 @@ function includesPath(subscriberId, path) {
485
486
  * `sources-synced` says the editor has sent everything it holds;
486
487
  * `confirmed` how far the server holds the editor's changes; a
487
488
  * `source-update` hands over one module's read, which the store keeps as it
488
- * is (`read`). A Studio from the release before sent the bare `source`
489
- * instead, and a page newer than the Studio it is open in -- a deploy rolling
490
- * out -- still takes that.
489
+ * is (`read`).
491
490
  *
492
491
  * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
493
492
  * provider had the same rule written inline.
@@ -532,17 +531,8 @@ function applyValEvent(store, detail) {
532
531
  changed: store.receive(moduleFilePath, read)
533
532
  };
534
533
  }
535
- // A Studio of the release before sent the bare `source`. This fallback
536
- // goes with the relay's `source` field: see "Release-delayed deletions"
537
- // in `docs/plans/one-content-model.md`.
538
- var source = "source" in detail ? detail.source : undefined;
539
- if (isJson(source)) {
540
- return {
541
- type: "updated",
542
- changed: store.update(moduleFilePath, source),
543
- fromPreviousStudio: true
544
- };
545
- }
534
+ // A bare `source` without `read` was a Studio of the release before
535
+ // the one content model; the release after it stopped reading it.
546
536
  }
547
537
  return {
548
538
  type: "invalid",
@@ -707,11 +697,6 @@ function isModuleFilePathOf(sources) {
707
697
  * moved what it holds (`changed`): its server render is older than what the
708
698
  * Studio has. A page rendered from the draft the Studio holds -- the
709
699
  * `draft` prop, read for this request -- is not refreshed for loading.
710
- * - **A Studio of the release before never says `confirmed`** (a deploy
711
- * rolling out: this page, that Studio). Its changes refresh the page as
712
- * they arrive (`changedByPreviousStudio`), as that release's page did,
713
- * until a `confirmed` says the Studio is this release's. They race the
714
- * write, as they did then; it lasts as long as the rollout.
715
700
  */
716
701
 
717
702
  function startRefreshLoop(options) {
@@ -745,13 +730,6 @@ function startRefreshLoop(options) {
745
730
  changed: function changed() {
746
731
  if (told === undefined) behind = true;
747
732
  },
748
- changedByPreviousStudio: function changedByPreviousStudio() {
749
- if (told !== undefined) {
750
- // A Studio that confirms: its `confirmed` is the refresh.
751
- return;
752
- }
753
- _run();
754
- },
755
733
  confirmed: function confirmed(seq) {
756
734
  if (told !== undefined && told !== null && seq !== null && seq <= told) {
757
735
  return;
@@ -1083,6 +1061,67 @@ function bundleSource(modules) {
1083
1061
  };
1084
1062
  }
1085
1063
 
1064
+ /**
1065
+ * What a page's hooks are told by the schema rule, kept as the set of
1066
+ * modules whose relayed content this page could not read, and announced each
1067
+ * time that set changes (`announce`).
1068
+ *
1069
+ * The rule runs while a component renders, so nothing is announced then: the
1070
+ * set is compared and announced once the render is over, in one microtask
1071
+ * for every module a render read. A module the page reads with its own
1072
+ * schema again -- its code caught up, which in local development is usually
1073
+ * a hot reload a moment after the Studio's -- leaves the set, so the notice
1074
+ * goes away by itself instead of asking for a reload nothing needs.
1075
+ */
1076
+
1077
+ function codeChangedReporter(announce) {
1078
+ var refused = new Map();
1079
+ var announced = [];
1080
+ var scheduled = false;
1081
+ var flush = function flush() {
1082
+ scheduled = false;
1083
+ var modules = _toConsumableArray(refused.keys()).sort();
1084
+ if (modules.join("\n") === announced.join("\n")) return;
1085
+ announced = modules;
1086
+ announce(modules);
1087
+ };
1088
+ var schemaChecked = function schemaChecked(path, other) {
1089
+ var before = refused.get(path);
1090
+ if (other === null) {
1091
+ if (before === undefined) return;
1092
+ refused["delete"](path);
1093
+ } else {
1094
+ if (before === other.schema) return;
1095
+ refused.set(path, other.schema);
1096
+ }
1097
+ if (scheduled) return;
1098
+ scheduled = true;
1099
+ queueMicrotask(flush);
1100
+ };
1101
+ return {
1102
+ schemaChecked: schemaChecked,
1103
+ modules: function modules() {
1104
+ return announced;
1105
+ }
1106
+ };
1107
+ }
1108
+
1109
+ /** The `val-overlay-spa` event that says {@link CodeChangedReporter.modules}. */
1110
+ function dispatchCodeChanged(modules) {
1111
+ var detail = {
1112
+ type: CODE_CHANGED_EVENT,
1113
+ modules: modules
1114
+ };
1115
+ window.dispatchEvent(new CustomEvent("val-overlay-spa", {
1116
+ detail: detail
1117
+ }));
1118
+ }
1119
+
1120
+ /** {@link codeChangedReporter} announcing to this window's Val overlay. */
1121
+ function windowCodeChangedReporter() {
1122
+ return codeChangedReporter(dispatchCodeChanged);
1123
+ }
1124
+
1086
1125
  /**
1087
1126
  * The rule that content is only read with the schema it was made for
1088
1127
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1122,10 +1161,20 @@ settled) {
1122
1161
  * promise: the code is changing (`codeChanged`), wait for it.
1123
1162
  */
1124
1163
  var schemaRule = function schemaRule(path, version, from) {
1164
+ var _rule$schemaChecked2;
1125
1165
  if (version === null || version === undefined || !rule) return null;
1126
1166
  var own = rule.schemaOf(path);
1127
- if (own === null || own === version.schema) return null;
1167
+ if (own === null) return null;
1168
+ if (own === version.schema) {
1169
+ var _rule$schemaChecked;
1170
+ (_rule$schemaChecked = rule.schemaChecked) === null || _rule$schemaChecked === void 0 || _rule$schemaChecked.call(rule, path, null);
1171
+ return null;
1172
+ }
1128
1173
  if (rule.codeChanged) return rule.codeChanged(path, version.schema);
1174
+ (_rule$schemaChecked2 = rule.schemaChecked) === null || _rule$schemaChecked2 === void 0 || _rule$schemaChecked2.call(rule, path, {
1175
+ schema: version.schema,
1176
+ from: from
1177
+ });
1129
1178
  Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1130
1179
  return "next";
1131
1180
  };
@@ -1294,13 +1343,15 @@ function readWork() {
1294
1343
 
1295
1344
  function viewOf(env, plan, settled) {
1296
1345
  var schemaVersionOf = env.schemaVersionOf;
1297
- return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2({
1346
+ return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2(_objectSpread2({
1298
1347
  schemaOf: function schemaOf(path) {
1299
1348
  var module = plan.own.get(path);
1300
1349
  return module === undefined ? null : schemaVersionOf(module);
1301
1350
  }
1302
1351
  }, env.codeChanged ? {
1303
1352
  codeChanged: env.codeChanged
1353
+ } : {}), env.schemaChecked ? {
1354
+ schemaChecked: env.schemaChecked
1304
1355
  } : {}) : undefined, settled);
1305
1356
  }
1306
1357
  function pending(waits) {
@@ -1864,4 +1915,4 @@ function readsOfFetchVal(fetchVal) {
1864
1915
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1865
1916
  }
1866
1917
 
1867
- export { ValExternalStore, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, createDraftStore, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal };
1918
+ export { ValExternalStore, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, codeChangedReporter, createDraftStore, dispatchCodeChanged, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal, windowCodeChangedReporter };
@@ -10,6 +10,7 @@ var _typeof = require('../../dist/typeof-b568f48f.cjs.dev.js');
10
10
  var core = require('@valbuild/core');
11
11
  var patch = require('@valbuild/core/patch');
12
12
  var slicedToArray = require('../../dist/slicedToArray-387314c6.cjs.dev.js');
13
+ var internal = require('@valbuild/shared/internal');
13
14
  require('@vercel/stega');
14
15
 
15
16
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -493,9 +494,7 @@ function includesPath(subscriberId, path) {
493
494
  * `sources-synced` says the editor has sent everything it holds;
494
495
  * `confirmed` how far the server holds the editor's changes; a
495
496
  * `source-update` hands over one module's read, which the store keeps as it
496
- * is (`read`). A Studio from the release before sent the bare `source`
497
- * instead, and a page newer than the Studio it is open in -- a deploy rolling
498
- * out -- still takes that.
497
+ * is (`read`).
499
498
  *
500
499
  * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
501
500
  * provider had the same rule written inline.
@@ -540,17 +539,8 @@ function applyValEvent(store, detail) {
540
539
  changed: store.receive(moduleFilePath, read)
541
540
  };
542
541
  }
543
- // A Studio of the release before sent the bare `source`. This fallback
544
- // goes with the relay's `source` field: see "Release-delayed deletions"
545
- // in `docs/plans/one-content-model.md`.
546
- var source = "source" in detail ? detail.source : undefined;
547
- if (isJson(source)) {
548
- return {
549
- type: "updated",
550
- changed: store.update(moduleFilePath, source),
551
- fromPreviousStudio: true
552
- };
553
- }
542
+ // A bare `source` without `read` was a Studio of the release before
543
+ // the one content model; the release after it stopped reading it.
554
544
  }
555
545
  return {
556
546
  type: "invalid",
@@ -715,11 +705,6 @@ function isModuleFilePathOf(sources) {
715
705
  * moved what it holds (`changed`): its server render is older than what the
716
706
  * Studio has. A page rendered from the draft the Studio holds -- the
717
707
  * `draft` prop, read for this request -- is not refreshed for loading.
718
- * - **A Studio of the release before never says `confirmed`** (a deploy
719
- * rolling out: this page, that Studio). Its changes refresh the page as
720
- * they arrive (`changedByPreviousStudio`), as that release's page did,
721
- * until a `confirmed` says the Studio is this release's. They race the
722
- * write, as they did then; it lasts as long as the rollout.
723
708
  */
724
709
 
725
710
  function startRefreshLoop(options) {
@@ -753,13 +738,6 @@ function startRefreshLoop(options) {
753
738
  changed: function changed() {
754
739
  if (told === undefined) behind = true;
755
740
  },
756
- changedByPreviousStudio: function changedByPreviousStudio() {
757
- if (told !== undefined) {
758
- // A Studio that confirms: its `confirmed` is the refresh.
759
- return;
760
- }
761
- _run();
762
- },
763
741
  confirmed: function confirmed(seq) {
764
742
  if (told !== undefined && told !== null && seq !== null && seq <= told) {
765
743
  return;
@@ -1091,6 +1069,67 @@ function bundleSource(modules) {
1091
1069
  };
1092
1070
  }
1093
1071
 
1072
+ /**
1073
+ * What a page's hooks are told by the schema rule, kept as the set of
1074
+ * modules whose relayed content this page could not read, and announced each
1075
+ * time that set changes (`announce`).
1076
+ *
1077
+ * The rule runs while a component renders, so nothing is announced then: the
1078
+ * set is compared and announced once the render is over, in one microtask
1079
+ * for every module a render read. A module the page reads with its own
1080
+ * schema again -- its code caught up, which in local development is usually
1081
+ * a hot reload a moment after the Studio's -- leaves the set, so the notice
1082
+ * goes away by itself instead of asking for a reload nothing needs.
1083
+ */
1084
+
1085
+ function codeChangedReporter(announce) {
1086
+ var refused = new Map();
1087
+ var announced = [];
1088
+ var scheduled = false;
1089
+ var flush = function flush() {
1090
+ scheduled = false;
1091
+ var modules = createForOfIteratorHelper._toConsumableArray(refused.keys()).sort();
1092
+ if (modules.join("\n") === announced.join("\n")) return;
1093
+ announced = modules;
1094
+ announce(modules);
1095
+ };
1096
+ var schemaChecked = function schemaChecked(path, other) {
1097
+ var before = refused.get(path);
1098
+ if (other === null) {
1099
+ if (before === undefined) return;
1100
+ refused["delete"](path);
1101
+ } else {
1102
+ if (before === other.schema) return;
1103
+ refused.set(path, other.schema);
1104
+ }
1105
+ if (scheduled) return;
1106
+ scheduled = true;
1107
+ queueMicrotask(flush);
1108
+ };
1109
+ return {
1110
+ schemaChecked: schemaChecked,
1111
+ modules: function modules() {
1112
+ return announced;
1113
+ }
1114
+ };
1115
+ }
1116
+
1117
+ /** The `val-overlay-spa` event that says {@link CodeChangedReporter.modules}. */
1118
+ function dispatchCodeChanged(modules) {
1119
+ var detail = {
1120
+ type: internal.CODE_CHANGED_EVENT,
1121
+ modules: modules
1122
+ };
1123
+ window.dispatchEvent(new CustomEvent("val-overlay-spa", {
1124
+ detail: detail
1125
+ }));
1126
+ }
1127
+
1128
+ /** {@link codeChangedReporter} announcing to this window's Val overlay. */
1129
+ function windowCodeChangedReporter() {
1130
+ return codeChangedReporter(dispatchCodeChanged);
1131
+ }
1132
+
1094
1133
  /**
1095
1134
  * The rule that content is only read with the schema it was made for
1096
1135
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1130,10 +1169,20 @@ settled) {
1130
1169
  * promise: the code is changing (`codeChanged`), wait for it.
1131
1170
  */
1132
1171
  var schemaRule = function schemaRule(path, version, from) {
1172
+ var _rule$schemaChecked2;
1133
1173
  if (version === null || version === undefined || !rule) return null;
1134
1174
  var own = rule.schemaOf(path);
1135
- if (own === null || own === version.schema) return null;
1175
+ if (own === null) return null;
1176
+ if (own === version.schema) {
1177
+ var _rule$schemaChecked;
1178
+ (_rule$schemaChecked = rule.schemaChecked) === null || _rule$schemaChecked === void 0 || _rule$schemaChecked.call(rule, path, null);
1179
+ return null;
1180
+ }
1136
1181
  if (rule.codeChanged) return rule.codeChanged(path, version.schema);
1182
+ (_rule$schemaChecked2 = rule.schemaChecked) === null || _rule$schemaChecked2 === void 0 || _rule$schemaChecked2.call(rule, path, {
1183
+ schema: version.schema,
1184
+ from: from
1185
+ });
1137
1186
  core.Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1138
1187
  return "next";
1139
1188
  };
@@ -1302,13 +1351,15 @@ function readWork() {
1302
1351
 
1303
1352
  function viewOf(env, plan, settled) {
1304
1353
  var schemaVersionOf = env.schemaVersionOf;
1305
- return layered([].concat(createForOfIteratorHelper._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? raw._objectSpread2({
1354
+ return layered([].concat(createForOfIteratorHelper._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? raw._objectSpread2(raw._objectSpread2({
1306
1355
  schemaOf: function schemaOf(path) {
1307
1356
  var module = plan.own.get(path);
1308
1357
  return module === undefined ? null : schemaVersionOf(module);
1309
1358
  }
1310
1359
  }, env.codeChanged ? {
1311
1360
  codeChanged: env.codeChanged
1361
+ } : {}), env.schemaChecked ? {
1362
+ schemaChecked: env.schemaChecked
1312
1363
  } : {}) : undefined, settled);
1313
1364
  }
1314
1365
  function pending(waits) {
@@ -1878,7 +1929,9 @@ exports.applyValEvent = applyValEvent;
1878
1929
  exports.awaitResolved = awaitResolved;
1879
1930
  exports.bundleSource = bundleSource;
1880
1931
  exports.bundledJsonEntryImport = bundledJsonEntryImport;
1932
+ exports.codeChangedReporter = codeChangedReporter;
1881
1933
  exports.createDraftStore = createDraftStore;
1934
+ exports.dispatchCodeChanged = dispatchCodeChanged;
1882
1935
  exports.draftHolds = draftHolds;
1883
1936
  exports.draftHoldsVersions = draftHoldsVersions;
1884
1937
  exports.entryOfModuleSource = entryOfModuleSource;
@@ -1900,3 +1953,4 @@ exports.startRefreshLoop = startRefreshLoop;
1900
1953
  exports.useResolved = useResolved;
1901
1954
  exports.useResolvedEntry = useResolvedEntry;
1902
1955
  exports.useResolvedVal = useResolvedVal;
1956
+ exports.windowCodeChangedReporter = windowCodeChangedReporter;
@@ -10,6 +10,7 @@ var _typeof = require('../../dist/typeof-16428c61.cjs.prod.js');
10
10
  var core = require('@valbuild/core');
11
11
  var patch = require('@valbuild/core/patch');
12
12
  var slicedToArray = require('../../dist/slicedToArray-64c83d56.cjs.prod.js');
13
+ var internal = require('@valbuild/shared/internal');
13
14
  require('@vercel/stega');
14
15
 
15
16
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -493,9 +494,7 @@ function includesPath(subscriberId, path) {
493
494
  * `sources-synced` says the editor has sent everything it holds;
494
495
  * `confirmed` how far the server holds the editor's changes; a
495
496
  * `source-update` hands over one module's read, which the store keeps as it
496
- * is (`read`). A Studio from the release before sent the bare `source`
497
- * instead, and a page newer than the Studio it is open in -- a deploy rolling
498
- * out -- still takes that.
497
+ * is (`read`).
499
498
  *
500
499
  * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
501
500
  * provider had the same rule written inline.
@@ -540,17 +539,8 @@ function applyValEvent(store, detail) {
540
539
  changed: store.receive(moduleFilePath, read)
541
540
  };
542
541
  }
543
- // A Studio of the release before sent the bare `source`. This fallback
544
- // goes with the relay's `source` field: see "Release-delayed deletions"
545
- // in `docs/plans/one-content-model.md`.
546
- var source = "source" in detail ? detail.source : undefined;
547
- if (isJson(source)) {
548
- return {
549
- type: "updated",
550
- changed: store.update(moduleFilePath, source),
551
- fromPreviousStudio: true
552
- };
553
- }
542
+ // A bare `source` without `read` was a Studio of the release before
543
+ // the one content model; the release after it stopped reading it.
554
544
  }
555
545
  return {
556
546
  type: "invalid",
@@ -715,11 +705,6 @@ function isModuleFilePathOf(sources) {
715
705
  * moved what it holds (`changed`): its server render is older than what the
716
706
  * Studio has. A page rendered from the draft the Studio holds -- the
717
707
  * `draft` prop, read for this request -- is not refreshed for loading.
718
- * - **A Studio of the release before never says `confirmed`** (a deploy
719
- * rolling out: this page, that Studio). Its changes refresh the page as
720
- * they arrive (`changedByPreviousStudio`), as that release's page did,
721
- * until a `confirmed` says the Studio is this release's. They race the
722
- * write, as they did then; it lasts as long as the rollout.
723
708
  */
724
709
 
725
710
  function startRefreshLoop(options) {
@@ -753,13 +738,6 @@ function startRefreshLoop(options) {
753
738
  changed: function changed() {
754
739
  if (told === undefined) behind = true;
755
740
  },
756
- changedByPreviousStudio: function changedByPreviousStudio() {
757
- if (told !== undefined) {
758
- // A Studio that confirms: its `confirmed` is the refresh.
759
- return;
760
- }
761
- _run();
762
- },
763
741
  confirmed: function confirmed(seq) {
764
742
  if (told !== undefined && told !== null && seq !== null && seq <= told) {
765
743
  return;
@@ -1091,6 +1069,67 @@ function bundleSource(modules) {
1091
1069
  };
1092
1070
  }
1093
1071
 
1072
+ /**
1073
+ * What a page's hooks are told by the schema rule, kept as the set of
1074
+ * modules whose relayed content this page could not read, and announced each
1075
+ * time that set changes (`announce`).
1076
+ *
1077
+ * The rule runs while a component renders, so nothing is announced then: the
1078
+ * set is compared and announced once the render is over, in one microtask
1079
+ * for every module a render read. A module the page reads with its own
1080
+ * schema again -- its code caught up, which in local development is usually
1081
+ * a hot reload a moment after the Studio's -- leaves the set, so the notice
1082
+ * goes away by itself instead of asking for a reload nothing needs.
1083
+ */
1084
+
1085
+ function codeChangedReporter(announce) {
1086
+ var refused = new Map();
1087
+ var announced = [];
1088
+ var scheduled = false;
1089
+ var flush = function flush() {
1090
+ scheduled = false;
1091
+ var modules = createForOfIteratorHelper._toConsumableArray(refused.keys()).sort();
1092
+ if (modules.join("\n") === announced.join("\n")) return;
1093
+ announced = modules;
1094
+ announce(modules);
1095
+ };
1096
+ var schemaChecked = function schemaChecked(path, other) {
1097
+ var before = refused.get(path);
1098
+ if (other === null) {
1099
+ if (before === undefined) return;
1100
+ refused["delete"](path);
1101
+ } else {
1102
+ if (before === other.schema) return;
1103
+ refused.set(path, other.schema);
1104
+ }
1105
+ if (scheduled) return;
1106
+ scheduled = true;
1107
+ queueMicrotask(flush);
1108
+ };
1109
+ return {
1110
+ schemaChecked: schemaChecked,
1111
+ modules: function modules() {
1112
+ return announced;
1113
+ }
1114
+ };
1115
+ }
1116
+
1117
+ /** The `val-overlay-spa` event that says {@link CodeChangedReporter.modules}. */
1118
+ function dispatchCodeChanged(modules) {
1119
+ var detail = {
1120
+ type: internal.CODE_CHANGED_EVENT,
1121
+ modules: modules
1122
+ };
1123
+ window.dispatchEvent(new CustomEvent("val-overlay-spa", {
1124
+ detail: detail
1125
+ }));
1126
+ }
1127
+
1128
+ /** {@link codeChangedReporter} announcing to this window's Val overlay. */
1129
+ function windowCodeChangedReporter() {
1130
+ return codeChangedReporter(dispatchCodeChanged);
1131
+ }
1132
+
1094
1133
  /**
1095
1134
  * The rule that content is only read with the schema it was made for
1096
1135
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1130,10 +1169,20 @@ settled) {
1130
1169
  * promise: the code is changing (`codeChanged`), wait for it.
1131
1170
  */
1132
1171
  var schemaRule = function schemaRule(path, version, from) {
1172
+ var _rule$schemaChecked2;
1133
1173
  if (version === null || version === undefined || !rule) return null;
1134
1174
  var own = rule.schemaOf(path);
1135
- if (own === null || own === version.schema) return null;
1175
+ if (own === null) return null;
1176
+ if (own === version.schema) {
1177
+ var _rule$schemaChecked;
1178
+ (_rule$schemaChecked = rule.schemaChecked) === null || _rule$schemaChecked === void 0 || _rule$schemaChecked.call(rule, path, null);
1179
+ return null;
1180
+ }
1136
1181
  if (rule.codeChanged) return rule.codeChanged(path, version.schema);
1182
+ (_rule$schemaChecked2 = rule.schemaChecked) === null || _rule$schemaChecked2 === void 0 || _rule$schemaChecked2.call(rule, path, {
1183
+ schema: version.schema,
1184
+ from: from
1185
+ });
1137
1186
  core.Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1138
1187
  return "next";
1139
1188
  };
@@ -1302,13 +1351,15 @@ function readWork() {
1302
1351
 
1303
1352
  function viewOf(env, plan, settled) {
1304
1353
  var schemaVersionOf = env.schemaVersionOf;
1305
- return layered([].concat(createForOfIteratorHelper._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? raw._objectSpread2({
1354
+ return layered([].concat(createForOfIteratorHelper._toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? raw._objectSpread2(raw._objectSpread2({
1306
1355
  schemaOf: function schemaOf(path) {
1307
1356
  var module = plan.own.get(path);
1308
1357
  return module === undefined ? null : schemaVersionOf(module);
1309
1358
  }
1310
1359
  }, env.codeChanged ? {
1311
1360
  codeChanged: env.codeChanged
1361
+ } : {}), env.schemaChecked ? {
1362
+ schemaChecked: env.schemaChecked
1312
1363
  } : {}) : undefined, settled);
1313
1364
  }
1314
1365
  function pending(waits) {
@@ -1878,7 +1929,9 @@ exports.applyValEvent = applyValEvent;
1878
1929
  exports.awaitResolved = awaitResolved;
1879
1930
  exports.bundleSource = bundleSource;
1880
1931
  exports.bundledJsonEntryImport = bundledJsonEntryImport;
1932
+ exports.codeChangedReporter = codeChangedReporter;
1881
1933
  exports.createDraftStore = createDraftStore;
1934
+ exports.dispatchCodeChanged = dispatchCodeChanged;
1882
1935
  exports.draftHolds = draftHolds;
1883
1936
  exports.draftHoldsVersions = draftHoldsVersions;
1884
1937
  exports.entryOfModuleSource = entryOfModuleSource;
@@ -1900,3 +1953,4 @@ exports.startRefreshLoop = startRefreshLoop;
1900
1953
  exports.useResolved = useResolved;
1901
1954
  exports.useResolvedEntry = useResolvedEntry;
1902
1955
  exports.useResolvedVal = useResolvedVal;
1956
+ exports.windowCodeChangedReporter = windowCodeChangedReporter;
@@ -6,6 +6,7 @@ import { _ as _typeof } from '../../dist/typeof-a1531d8f.esm.js';
6
6
  import { Internal, RecordSchema } from '@valbuild/core';
7
7
  import { deepEqual } from '@valbuild/core/patch';
8
8
  import { _ as _slicedToArray } from '../../dist/slicedToArray-70ecb9da.esm.js';
9
+ import { CODE_CHANGED_EVENT } from '@valbuild/shared/internal';
9
10
  import '@vercel/stega';
10
11
 
11
12
  function _objectWithoutPropertiesLoose(r, e) {
@@ -485,9 +486,7 @@ function includesPath(subscriberId, path) {
485
486
  * `sources-synced` says the editor has sent everything it holds;
486
487
  * `confirmed` how far the server holds the editor's changes; a
487
488
  * `source-update` hands over one module's read, which the store keeps as it
488
- * is (`read`). A Studio from the release before sent the bare `source`
489
- * instead, and a page newer than the Studio it is open in -- a deploy rolling
490
- * out -- still takes that.
489
+ * is (`read`).
491
490
  *
492
491
  * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
493
492
  * provider had the same rule written inline.
@@ -532,17 +531,8 @@ function applyValEvent(store, detail) {
532
531
  changed: store.receive(moduleFilePath, read)
533
532
  };
534
533
  }
535
- // A Studio of the release before sent the bare `source`. This fallback
536
- // goes with the relay's `source` field: see "Release-delayed deletions"
537
- // in `docs/plans/one-content-model.md`.
538
- var source = "source" in detail ? detail.source : undefined;
539
- if (isJson(source)) {
540
- return {
541
- type: "updated",
542
- changed: store.update(moduleFilePath, source),
543
- fromPreviousStudio: true
544
- };
545
- }
534
+ // A bare `source` without `read` was a Studio of the release before
535
+ // the one content model; the release after it stopped reading it.
546
536
  }
547
537
  return {
548
538
  type: "invalid",
@@ -707,11 +697,6 @@ function isModuleFilePathOf(sources) {
707
697
  * moved what it holds (`changed`): its server render is older than what the
708
698
  * Studio has. A page rendered from the draft the Studio holds -- the
709
699
  * `draft` prop, read for this request -- is not refreshed for loading.
710
- * - **A Studio of the release before never says `confirmed`** (a deploy
711
- * rolling out: this page, that Studio). Its changes refresh the page as
712
- * they arrive (`changedByPreviousStudio`), as that release's page did,
713
- * until a `confirmed` says the Studio is this release's. They race the
714
- * write, as they did then; it lasts as long as the rollout.
715
700
  */
716
701
 
717
702
  function startRefreshLoop(options) {
@@ -745,13 +730,6 @@ function startRefreshLoop(options) {
745
730
  changed: function changed() {
746
731
  if (told === undefined) behind = true;
747
732
  },
748
- changedByPreviousStudio: function changedByPreviousStudio() {
749
- if (told !== undefined) {
750
- // A Studio that confirms: its `confirmed` is the refresh.
751
- return;
752
- }
753
- _run();
754
- },
755
733
  confirmed: function confirmed(seq) {
756
734
  if (told !== undefined && told !== null && seq !== null && seq <= told) {
757
735
  return;
@@ -1083,6 +1061,67 @@ function bundleSource(modules) {
1083
1061
  };
1084
1062
  }
1085
1063
 
1064
+ /**
1065
+ * What a page's hooks are told by the schema rule, kept as the set of
1066
+ * modules whose relayed content this page could not read, and announced each
1067
+ * time that set changes (`announce`).
1068
+ *
1069
+ * The rule runs while a component renders, so nothing is announced then: the
1070
+ * set is compared and announced once the render is over, in one microtask
1071
+ * for every module a render read. A module the page reads with its own
1072
+ * schema again -- its code caught up, which in local development is usually
1073
+ * a hot reload a moment after the Studio's -- leaves the set, so the notice
1074
+ * goes away by itself instead of asking for a reload nothing needs.
1075
+ */
1076
+
1077
+ function codeChangedReporter(announce) {
1078
+ var refused = new Map();
1079
+ var announced = [];
1080
+ var scheduled = false;
1081
+ var flush = function flush() {
1082
+ scheduled = false;
1083
+ var modules = _toConsumableArray(refused.keys()).sort();
1084
+ if (modules.join("\n") === announced.join("\n")) return;
1085
+ announced = modules;
1086
+ announce(modules);
1087
+ };
1088
+ var schemaChecked = function schemaChecked(path, other) {
1089
+ var before = refused.get(path);
1090
+ if (other === null) {
1091
+ if (before === undefined) return;
1092
+ refused["delete"](path);
1093
+ } else {
1094
+ if (before === other.schema) return;
1095
+ refused.set(path, other.schema);
1096
+ }
1097
+ if (scheduled) return;
1098
+ scheduled = true;
1099
+ queueMicrotask(flush);
1100
+ };
1101
+ return {
1102
+ schemaChecked: schemaChecked,
1103
+ modules: function modules() {
1104
+ return announced;
1105
+ }
1106
+ };
1107
+ }
1108
+
1109
+ /** The `val-overlay-spa` event that says {@link CodeChangedReporter.modules}. */
1110
+ function dispatchCodeChanged(modules) {
1111
+ var detail = {
1112
+ type: CODE_CHANGED_EVENT,
1113
+ modules: modules
1114
+ };
1115
+ window.dispatchEvent(new CustomEvent("val-overlay-spa", {
1116
+ detail: detail
1117
+ }));
1118
+ }
1119
+
1120
+ /** {@link codeChangedReporter} announcing to this window's Val overlay. */
1121
+ function windowCodeChangedReporter() {
1122
+ return codeChangedReporter(dispatchCodeChanged);
1123
+ }
1124
+
1086
1125
  /**
1087
1126
  * The rule that content is only read with the schema it was made for
1088
1127
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1122,10 +1161,20 @@ settled) {
1122
1161
  * promise: the code is changing (`codeChanged`), wait for it.
1123
1162
  */
1124
1163
  var schemaRule = function schemaRule(path, version, from) {
1164
+ var _rule$schemaChecked2;
1125
1165
  if (version === null || version === undefined || !rule) return null;
1126
1166
  var own = rule.schemaOf(path);
1127
- if (own === null || own === version.schema) return null;
1167
+ if (own === null) return null;
1168
+ if (own === version.schema) {
1169
+ var _rule$schemaChecked;
1170
+ (_rule$schemaChecked = rule.schemaChecked) === null || _rule$schemaChecked === void 0 || _rule$schemaChecked.call(rule, path, null);
1171
+ return null;
1172
+ }
1128
1173
  if (rule.codeChanged) return rule.codeChanged(path, version.schema);
1174
+ (_rule$schemaChecked2 = rule.schemaChecked) === null || _rule$schemaChecked2 === void 0 || _rule$schemaChecked2.call(rule, path, {
1175
+ schema: version.schema,
1176
+ from: from
1177
+ });
1129
1178
  Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1130
1179
  return "next";
1131
1180
  };
@@ -1294,13 +1343,15 @@ function readWork() {
1294
1343
 
1295
1344
  function viewOf(env, plan, settled) {
1296
1345
  var schemaVersionOf = env.schemaVersionOf;
1297
- return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2({
1346
+ return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2(_objectSpread2({
1298
1347
  schemaOf: function schemaOf(path) {
1299
1348
  var module = plan.own.get(path);
1300
1349
  return module === undefined ? null : schemaVersionOf(module);
1301
1350
  }
1302
1351
  }, env.codeChanged ? {
1303
1352
  codeChanged: env.codeChanged
1353
+ } : {}), env.schemaChecked ? {
1354
+ schemaChecked: env.schemaChecked
1304
1355
  } : {}) : undefined, settled);
1305
1356
  }
1306
1357
  function pending(waits) {
@@ -1864,4 +1915,4 @@ function readsOfFetchVal(fetchVal) {
1864
1915
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1865
1916
  }
1866
1917
 
1867
- export { ValExternalStore, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, createDraftStore, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal };
1918
+ export { ValExternalStore, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, codeChangedReporter, createDraftStore, dispatchCodeChanged, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal, windowCodeChangedReporter };
@@ -6,6 +6,7 @@ import { _ as _typeof } from '../../dist/typeof-e0c837cc.worker.esm.js';
6
6
  import { Internal, RecordSchema } from '@valbuild/core';
7
7
  import { deepEqual } from '@valbuild/core/patch';
8
8
  import { _ as _slicedToArray } from '../../dist/slicedToArray-106ca5f3.worker.esm.js';
9
+ import { CODE_CHANGED_EVENT } from '@valbuild/shared/internal';
9
10
  import '@vercel/stega';
10
11
 
11
12
  function _objectWithoutPropertiesLoose(r, e) {
@@ -485,9 +486,7 @@ function includesPath(subscriberId, path) {
485
486
  * `sources-synced` says the editor has sent everything it holds;
486
487
  * `confirmed` how far the server holds the editor's changes; a
487
488
  * `source-update` hands over one module's read, which the store keeps as it
488
- * is (`read`). A Studio from the release before sent the bare `source`
489
- * instead, and a page newer than the Studio it is open in -- a deploy rolling
490
- * out -- still takes that.
489
+ * is (`read`).
491
490
  *
492
491
  * Moved here from `@valbuild/tanstack`'s draft store; `@valbuild/next`'s
493
492
  * provider had the same rule written inline.
@@ -532,17 +531,8 @@ function applyValEvent(store, detail) {
532
531
  changed: store.receive(moduleFilePath, read)
533
532
  };
534
533
  }
535
- // A Studio of the release before sent the bare `source`. This fallback
536
- // goes with the relay's `source` field: see "Release-delayed deletions"
537
- // in `docs/plans/one-content-model.md`.
538
- var source = "source" in detail ? detail.source : undefined;
539
- if (isJson(source)) {
540
- return {
541
- type: "updated",
542
- changed: store.update(moduleFilePath, source),
543
- fromPreviousStudio: true
544
- };
545
- }
534
+ // A bare `source` without `read` was a Studio of the release before
535
+ // the one content model; the release after it stopped reading it.
546
536
  }
547
537
  return {
548
538
  type: "invalid",
@@ -707,11 +697,6 @@ function isModuleFilePathOf(sources) {
707
697
  * moved what it holds (`changed`): its server render is older than what the
708
698
  * Studio has. A page rendered from the draft the Studio holds -- the
709
699
  * `draft` prop, read for this request -- is not refreshed for loading.
710
- * - **A Studio of the release before never says `confirmed`** (a deploy
711
- * rolling out: this page, that Studio). Its changes refresh the page as
712
- * they arrive (`changedByPreviousStudio`), as that release's page did,
713
- * until a `confirmed` says the Studio is this release's. They race the
714
- * write, as they did then; it lasts as long as the rollout.
715
700
  */
716
701
 
717
702
  function startRefreshLoop(options) {
@@ -745,13 +730,6 @@ function startRefreshLoop(options) {
745
730
  changed: function changed() {
746
731
  if (told === undefined) behind = true;
747
732
  },
748
- changedByPreviousStudio: function changedByPreviousStudio() {
749
- if (told !== undefined) {
750
- // A Studio that confirms: its `confirmed` is the refresh.
751
- return;
752
- }
753
- _run();
754
- },
755
733
  confirmed: function confirmed(seq) {
756
734
  if (told !== undefined && told !== null && seq !== null && seq <= told) {
757
735
  return;
@@ -1083,6 +1061,67 @@ function bundleSource(modules) {
1083
1061
  };
1084
1062
  }
1085
1063
 
1064
+ /**
1065
+ * What a page's hooks are told by the schema rule, kept as the set of
1066
+ * modules whose relayed content this page could not read, and announced each
1067
+ * time that set changes (`announce`).
1068
+ *
1069
+ * The rule runs while a component renders, so nothing is announced then: the
1070
+ * set is compared and announced once the render is over, in one microtask
1071
+ * for every module a render read. A module the page reads with its own
1072
+ * schema again -- its code caught up, which in local development is usually
1073
+ * a hot reload a moment after the Studio's -- leaves the set, so the notice
1074
+ * goes away by itself instead of asking for a reload nothing needs.
1075
+ */
1076
+
1077
+ function codeChangedReporter(announce) {
1078
+ var refused = new Map();
1079
+ var announced = [];
1080
+ var scheduled = false;
1081
+ var flush = function flush() {
1082
+ scheduled = false;
1083
+ var modules = _toConsumableArray(refused.keys()).sort();
1084
+ if (modules.join("\n") === announced.join("\n")) return;
1085
+ announced = modules;
1086
+ announce(modules);
1087
+ };
1088
+ var schemaChecked = function schemaChecked(path, other) {
1089
+ var before = refused.get(path);
1090
+ if (other === null) {
1091
+ if (before === undefined) return;
1092
+ refused["delete"](path);
1093
+ } else {
1094
+ if (before === other.schema) return;
1095
+ refused.set(path, other.schema);
1096
+ }
1097
+ if (scheduled) return;
1098
+ scheduled = true;
1099
+ queueMicrotask(flush);
1100
+ };
1101
+ return {
1102
+ schemaChecked: schemaChecked,
1103
+ modules: function modules() {
1104
+ return announced;
1105
+ }
1106
+ };
1107
+ }
1108
+
1109
+ /** The `val-overlay-spa` event that says {@link CodeChangedReporter.modules}. */
1110
+ function dispatchCodeChanged(modules) {
1111
+ var detail = {
1112
+ type: CODE_CHANGED_EVENT,
1113
+ modules: modules
1114
+ };
1115
+ window.dispatchEvent(new CustomEvent("val-overlay-spa", {
1116
+ detail: detail
1117
+ }));
1118
+ }
1119
+
1120
+ /** {@link codeChangedReporter} announcing to this window's Val overlay. */
1121
+ function windowCodeChangedReporter() {
1122
+ return codeChangedReporter(dispatchCodeChanged);
1123
+ }
1124
+
1086
1125
  /**
1087
1126
  * The rule that content is only read with the schema it was made for
1088
1127
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1122,10 +1161,20 @@ settled) {
1122
1161
  * promise: the code is changing (`codeChanged`), wait for it.
1123
1162
  */
1124
1163
  var schemaRule = function schemaRule(path, version, from) {
1164
+ var _rule$schemaChecked2;
1125
1165
  if (version === null || version === undefined || !rule) return null;
1126
1166
  var own = rule.schemaOf(path);
1127
- if (own === null || own === version.schema) return null;
1167
+ if (own === null) return null;
1168
+ if (own === version.schema) {
1169
+ var _rule$schemaChecked;
1170
+ (_rule$schemaChecked = rule.schemaChecked) === null || _rule$schemaChecked === void 0 || _rule$schemaChecked.call(rule, path, null);
1171
+ return null;
1172
+ }
1128
1173
  if (rule.codeChanged) return rule.codeChanged(path, version.schema);
1174
+ (_rule$schemaChecked2 = rule.schemaChecked) === null || _rule$schemaChecked2 === void 0 || _rule$schemaChecked2.call(rule, path, {
1175
+ schema: version.schema,
1176
+ from: from
1177
+ });
1129
1178
  Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1130
1179
  return "next";
1131
1180
  };
@@ -1294,13 +1343,15 @@ function readWork() {
1294
1343
 
1295
1344
  function viewOf(env, plan, settled) {
1296
1345
  var schemaVersionOf = env.schemaVersionOf;
1297
- return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2({
1346
+ return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2(_objectSpread2({
1298
1347
  schemaOf: function schemaOf(path) {
1299
1348
  var module = plan.own.get(path);
1300
1349
  return module === undefined ? null : schemaVersionOf(module);
1301
1350
  }
1302
1351
  }, env.codeChanged ? {
1303
1352
  codeChanged: env.codeChanged
1353
+ } : {}), env.schemaChecked ? {
1354
+ schemaChecked: env.schemaChecked
1304
1355
  } : {}) : undefined, settled);
1305
1356
  }
1306
1357
  function pending(waits) {
@@ -1864,4 +1915,4 @@ function readsOfFetchVal(fetchVal) {
1864
1915
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1865
1916
  }
1866
1917
 
1867
- export { ValExternalStore, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, createDraftStore, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal };
1918
+ export { ValExternalStore, ValRichText, applyValEvent, awaitResolved, bundleSource, bundledJsonEntryImport, codeChangedReporter, createDraftStore, dispatchCodeChanged, draftHolds, draftHoldsVersions, entryOfModuleSource, fetchValFrom, getJsonEntryStegaRoot, isDraft, isJsonValuesRecordSchema, layered, mapResolution, overlaySource, planOf, readWork, readsOfFetchVal, resolveModuleEntry, resolveVal, resolveValEntry, snapshotSource, startRefreshLoop, useResolved, useResolvedEntry, useResolvedVal, windowCodeChangedReporter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/react",
3
- "version": "0.152.2",
3
+ "version": "0.153.1",
4
4
  "private": false,
5
5
  "description": "Val - React internal helpers",
6
6
  "repository": {
@@ -11,9 +11,9 @@
11
11
  "dependencies": {
12
12
  "@vercel/stega": "^1.1.0",
13
13
  "base64-arraybuffer": "^1.0.2",
14
- "@valbuild/core": "0.151.0",
15
- "@valbuild/shared": "0.152.1",
16
- "@valbuild/ui": "0.152.2"
14
+ "@valbuild/core": "0.153.0",
15
+ "@valbuild/shared": "0.153.1",
16
+ "@valbuild/ui": "0.153.1"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@testing-library/react": "^16.3.3",