@valbuild/react 0.153.0 → 0.153.2

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,21 @@
1
1
  # @valbuild/react
2
2
 
3
+ ## 0.153.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`75877d7`](https://github.com/valbuild/val/commit/75877d704582abdc1bfb14902b311a857066261a)]:
8
+ - @valbuild/ui@0.153.2
9
+
10
+ ## 0.153.1
11
+
12
+ ### Patch Changes
13
+
14
+ - [#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.
15
+ - 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)]:
16
+ - @valbuild/shared@0.153.1
17
+ - @valbuild/ui@0.153.1
18
+
3
19
  ## 0.153.0
4
20
 
5
21
  ### Minor 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;
@@ -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 = {
@@ -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) {
@@ -1060,6 +1061,67 @@ function bundleSource(modules) {
1060
1061
  };
1061
1062
  }
1062
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
+
1063
1125
  /**
1064
1126
  * The rule that content is only read with the schema it was made for
1065
1127
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1099,10 +1161,20 @@ settled) {
1099
1161
  * promise: the code is changing (`codeChanged`), wait for it.
1100
1162
  */
1101
1163
  var schemaRule = function schemaRule(path, version, from) {
1164
+ var _rule$schemaChecked2;
1102
1165
  if (version === null || version === undefined || !rule) return null;
1103
1166
  var own = rule.schemaOf(path);
1104
- 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
+ }
1105
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
+ });
1106
1178
  Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1107
1179
  return "next";
1108
1180
  };
@@ -1271,13 +1343,15 @@ function readWork() {
1271
1343
 
1272
1344
  function viewOf(env, plan, settled) {
1273
1345
  var schemaVersionOf = env.schemaVersionOf;
1274
- return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2({
1346
+ return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2(_objectSpread2({
1275
1347
  schemaOf: function schemaOf(path) {
1276
1348
  var module = plan.own.get(path);
1277
1349
  return module === undefined ? null : schemaVersionOf(module);
1278
1350
  }
1279
1351
  }, env.codeChanged ? {
1280
1352
  codeChanged: env.codeChanged
1353
+ } : {}), env.schemaChecked ? {
1354
+ schemaChecked: env.schemaChecked
1281
1355
  } : {}) : undefined, settled);
1282
1356
  }
1283
1357
  function pending(waits) {
@@ -1841,4 +1915,4 @@ function readsOfFetchVal(fetchVal) {
1841
1915
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1842
1916
  }
1843
1917
 
1844
- 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 }; }
@@ -1068,6 +1069,67 @@ function bundleSource(modules) {
1068
1069
  };
1069
1070
  }
1070
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
+
1071
1133
  /**
1072
1134
  * The rule that content is only read with the schema it was made for
1073
1135
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1107,10 +1169,20 @@ settled) {
1107
1169
  * promise: the code is changing (`codeChanged`), wait for it.
1108
1170
  */
1109
1171
  var schemaRule = function schemaRule(path, version, from) {
1172
+ var _rule$schemaChecked2;
1110
1173
  if (version === null || version === undefined || !rule) return null;
1111
1174
  var own = rule.schemaOf(path);
1112
- 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
+ }
1113
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
+ });
1114
1186
  core.Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1115
1187
  return "next";
1116
1188
  };
@@ -1279,13 +1351,15 @@ function readWork() {
1279
1351
 
1280
1352
  function viewOf(env, plan, settled) {
1281
1353
  var schemaVersionOf = env.schemaVersionOf;
1282
- 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({
1283
1355
  schemaOf: function schemaOf(path) {
1284
1356
  var module = plan.own.get(path);
1285
1357
  return module === undefined ? null : schemaVersionOf(module);
1286
1358
  }
1287
1359
  }, env.codeChanged ? {
1288
1360
  codeChanged: env.codeChanged
1361
+ } : {}), env.schemaChecked ? {
1362
+ schemaChecked: env.schemaChecked
1289
1363
  } : {}) : undefined, settled);
1290
1364
  }
1291
1365
  function pending(waits) {
@@ -1855,7 +1929,9 @@ exports.applyValEvent = applyValEvent;
1855
1929
  exports.awaitResolved = awaitResolved;
1856
1930
  exports.bundleSource = bundleSource;
1857
1931
  exports.bundledJsonEntryImport = bundledJsonEntryImport;
1932
+ exports.codeChangedReporter = codeChangedReporter;
1858
1933
  exports.createDraftStore = createDraftStore;
1934
+ exports.dispatchCodeChanged = dispatchCodeChanged;
1859
1935
  exports.draftHolds = draftHolds;
1860
1936
  exports.draftHoldsVersions = draftHoldsVersions;
1861
1937
  exports.entryOfModuleSource = entryOfModuleSource;
@@ -1877,3 +1953,4 @@ exports.startRefreshLoop = startRefreshLoop;
1877
1953
  exports.useResolved = useResolved;
1878
1954
  exports.useResolvedEntry = useResolvedEntry;
1879
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 }; }
@@ -1068,6 +1069,67 @@ function bundleSource(modules) {
1068
1069
  };
1069
1070
  }
1070
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
+
1071
1133
  /**
1072
1134
  * The rule that content is only read with the schema it was made for
1073
1135
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1107,10 +1169,20 @@ settled) {
1107
1169
  * promise: the code is changing (`codeChanged`), wait for it.
1108
1170
  */
1109
1171
  var schemaRule = function schemaRule(path, version, from) {
1172
+ var _rule$schemaChecked2;
1110
1173
  if (version === null || version === undefined || !rule) return null;
1111
1174
  var own = rule.schemaOf(path);
1112
- 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
+ }
1113
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
+ });
1114
1186
  core.Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1115
1187
  return "next";
1116
1188
  };
@@ -1279,13 +1351,15 @@ function readWork() {
1279
1351
 
1280
1352
  function viewOf(env, plan, settled) {
1281
1353
  var schemaVersionOf = env.schemaVersionOf;
1282
- 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({
1283
1355
  schemaOf: function schemaOf(path) {
1284
1356
  var module = plan.own.get(path);
1285
1357
  return module === undefined ? null : schemaVersionOf(module);
1286
1358
  }
1287
1359
  }, env.codeChanged ? {
1288
1360
  codeChanged: env.codeChanged
1361
+ } : {}), env.schemaChecked ? {
1362
+ schemaChecked: env.schemaChecked
1289
1363
  } : {}) : undefined, settled);
1290
1364
  }
1291
1365
  function pending(waits) {
@@ -1855,7 +1929,9 @@ exports.applyValEvent = applyValEvent;
1855
1929
  exports.awaitResolved = awaitResolved;
1856
1930
  exports.bundleSource = bundleSource;
1857
1931
  exports.bundledJsonEntryImport = bundledJsonEntryImport;
1932
+ exports.codeChangedReporter = codeChangedReporter;
1858
1933
  exports.createDraftStore = createDraftStore;
1934
+ exports.dispatchCodeChanged = dispatchCodeChanged;
1859
1935
  exports.draftHolds = draftHolds;
1860
1936
  exports.draftHoldsVersions = draftHoldsVersions;
1861
1937
  exports.entryOfModuleSource = entryOfModuleSource;
@@ -1877,3 +1953,4 @@ exports.startRefreshLoop = startRefreshLoop;
1877
1953
  exports.useResolved = useResolved;
1878
1954
  exports.useResolvedEntry = useResolvedEntry;
1879
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) {
@@ -1060,6 +1061,67 @@ function bundleSource(modules) {
1060
1061
  };
1061
1062
  }
1062
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
+
1063
1125
  /**
1064
1126
  * The rule that content is only read with the schema it was made for
1065
1127
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1099,10 +1161,20 @@ settled) {
1099
1161
  * promise: the code is changing (`codeChanged`), wait for it.
1100
1162
  */
1101
1163
  var schemaRule = function schemaRule(path, version, from) {
1164
+ var _rule$schemaChecked2;
1102
1165
  if (version === null || version === undefined || !rule) return null;
1103
1166
  var own = rule.schemaOf(path);
1104
- 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
+ }
1105
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
+ });
1106
1178
  Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1107
1179
  return "next";
1108
1180
  };
@@ -1271,13 +1343,15 @@ function readWork() {
1271
1343
 
1272
1344
  function viewOf(env, plan, settled) {
1273
1345
  var schemaVersionOf = env.schemaVersionOf;
1274
- return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2({
1346
+ return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2(_objectSpread2({
1275
1347
  schemaOf: function schemaOf(path) {
1276
1348
  var module = plan.own.get(path);
1277
1349
  return module === undefined ? null : schemaVersionOf(module);
1278
1350
  }
1279
1351
  }, env.codeChanged ? {
1280
1352
  codeChanged: env.codeChanged
1353
+ } : {}), env.schemaChecked ? {
1354
+ schemaChecked: env.schemaChecked
1281
1355
  } : {}) : undefined, settled);
1282
1356
  }
1283
1357
  function pending(waits) {
@@ -1841,4 +1915,4 @@ function readsOfFetchVal(fetchVal) {
1841
1915
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1842
1916
  }
1843
1917
 
1844
- 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) {
@@ -1060,6 +1061,67 @@ function bundleSource(modules) {
1060
1061
  };
1061
1062
  }
1062
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
+
1063
1125
  /**
1064
1126
  * The rule that content is only read with the schema it was made for
1065
1127
  * (`docs/plans/one-content-model.md`, goal 3).
@@ -1099,10 +1161,20 @@ settled) {
1099
1161
  * promise: the code is changing (`codeChanged`), wait for it.
1100
1162
  */
1101
1163
  var schemaRule = function schemaRule(path, version, from) {
1164
+ var _rule$schemaChecked2;
1102
1165
  if (version === null || version === undefined || !rule) return null;
1103
1166
  var own = rule.schemaOf(path);
1104
- 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
+ }
1105
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
+ });
1106
1178
  Internal.log.debug("".concat(path, " from ").concat(from, " was made with another schema than this code has; reading the next source"));
1107
1179
  return "next";
1108
1180
  };
@@ -1271,13 +1343,15 @@ function readWork() {
1271
1343
 
1272
1344
  function viewOf(env, plan, settled) {
1273
1345
  var schemaVersionOf = env.schemaVersionOf;
1274
- return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2({
1346
+ return layered([].concat(_toConsumableArray(env.sources), [bundleSource(plan.own)]), schemaVersionOf ? _objectSpread2(_objectSpread2({
1275
1347
  schemaOf: function schemaOf(path) {
1276
1348
  var module = plan.own.get(path);
1277
1349
  return module === undefined ? null : schemaVersionOf(module);
1278
1350
  }
1279
1351
  }, env.codeChanged ? {
1280
1352
  codeChanged: env.codeChanged
1353
+ } : {}), env.schemaChecked ? {
1354
+ schemaChecked: env.schemaChecked
1281
1355
  } : {}) : undefined, settled);
1282
1356
  }
1283
1357
  function pending(waits) {
@@ -1841,4 +1915,4 @@ function readsOfFetchVal(fetchVal) {
1841
1915
  return (_fetchValReads$get = fetchValReads.get(fetchVal)) !== null && _fetchValReads$get !== void 0 ? _fetchValReads$get : null;
1842
1916
  }
1843
1917
 
1844
- 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.153.0",
3
+ "version": "0.153.2",
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.153.0",
15
- "@valbuild/shared": "0.153.0",
16
- "@valbuild/ui": "0.153.0"
14
+ "@valbuild/ui": "0.153.2",
15
+ "@valbuild/shared": "0.153.1",
16
+ "@valbuild/core": "0.153.0"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@testing-library/react": "^16.3.3",