@valbuild/tanstack 0.153.5 → 0.154.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
6
6
  var _typeof = require('./typeof-bd6ec82c.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
9
- var version = require('./version-fb089780.cjs.dev.js');
9
+ var version = require('./version-208d50df.cjs.dev.js');
10
10
  var internal = require('@valbuild/react/internal');
11
11
  var ui = require('@valbuild/ui');
12
12
  var reactRouter = require('@tanstack/react-router');
@@ -263,6 +263,13 @@ var DEFAULT_SELECTION = {
263
263
  */
264
264
  var RESCAN_INTERVAL_MS = 5000;
265
265
 
266
+ /**
267
+ * This document, among the ones the frame loads: sent with every `ready`
268
+ * (see `document` there). Made when the module is evaluated, which is once
269
+ * per document. Not `crypto.randomUUID`, which an insecure context lacks.
270
+ */
271
+ var DOCUMENT_ID = "".concat(Date.now().toString(36), "-").concat(Math.random().toString(36).slice(2));
272
+
266
273
  /**
267
274
  * The page's half of the canvas protocol.
268
275
  *
@@ -327,6 +334,50 @@ function ValCanvasBridge(_ref) {
327
334
  return (_stopRestoring$curren = stopRestoring.current) === null || _stopRestoring$curren === void 0 ? void 0 : _stopRestoring$curren.call(stopRestoring);
328
335
  };
329
336
  }, []);
337
+ /**
338
+ * The field being edited on the page itself (`editInline`), or the last
339
+ * one that was, while its copy waits for the page to catch up. See
340
+ * `inlineEditing.ts` in `@valbuild/shared`, which both bindings run.
341
+ */
342
+ var inlineEditing = React__default["default"].useRef(null);
343
+ React__default["default"].useEffect(function () {
344
+ return function () {
345
+ var _inlineEditing$curren;
346
+ return (_inlineEditing$curren = inlineEditing.current) === null || _inlineEditing$curren === void 0 ? void 0 : _inlineEditing$curren.release();
347
+ };
348
+ }, []);
349
+ /**
350
+ * The last pick: the element and where on it. `editInline` is the Studio's
351
+ * answer to a `clicked`, and the caret belongs where that click was.
352
+ */
353
+ var lastPick = React__default["default"].useRef(null);
354
+ /**
355
+ * The page's texts as the Studio last said (`textFields`), and the origin
356
+ * that said it, which is the only one an edit started from them answers.
357
+ * `null` until it says: a Studio that predates it never does, and every
358
+ * click then asks, as before.
359
+ */
360
+ var textFields = React__default["default"].useRef(null);
361
+ /**
362
+ * Whether the edit in progress was started here, in a click, rather than
363
+ * by `editInline`: an `editInline` that arrives after it answers a click
364
+ * from before it, and must not take the caret away.
365
+ */
366
+ var startedOnClick = React__default["default"].useRef(false);
367
+ /**
368
+ * The keys pressed since a click the Studio was asked about, until it
369
+ * answers: see `inlineEditKeys.ts`.
370
+ */
371
+ var heldKeys = React__default["default"].useRef(null);
372
+ React__default["default"].useEffect(function () {
373
+ return function () {
374
+ var _heldKeys$current;
375
+ (_heldKeys$current = heldKeys.current) === null || _heldKeys$current === void 0 || _heldKeys$current.release();
376
+ };
377
+ }, []);
378
+ // Read when an edit starts, long after the render that set it.
379
+ var selectionColor = React__default["default"].useRef(selectionColors.selection);
380
+ selectionColor.current = selectionColors.selection;
330
381
  var post = React__default["default"].useCallback(function (message) {
331
382
  // `*` as the target origin: the studio and the page share an origin today,
332
383
  // but the frame does not know the parent's origin for certain and naming
@@ -348,6 +399,10 @@ function ValCanvasBridge(_ref) {
348
399
 
349
400
  /** Every element Val tagged, with where it is on the page. */
350
401
  var scan = React__default["default"].useCallback(function () {
402
+ var _textFields$current$e, _textFields$current;
403
+ // Before measuring: an emptied text measures with the room it is given
404
+ // while Select is on, so the Studio's outline of it has a size too.
405
+ client.markEmptyTextFields(document, pickingRef.current ? (_textFields$current$e = (_textFields$current = textFields.current) === null || _textFields$current === void 0 ? void 0 : _textFields$current.empty) !== null && _textFields$current$e !== void 0 ? _textFields$current$e : NO_PATHS : NO_PATHS, core.Internal.splitJoinedSourcePaths);
351
406
  var elements = [];
352
407
  var scrollX = window.scrollX;
353
408
  var scrollY = window.scrollY;
@@ -425,7 +480,7 @@ function ValCanvasBridge(_ref) {
425
480
 
426
481
  // Announce the frame, and say whether it is actually showing draft content.
427
482
  React__default["default"].useEffect(function () {
428
- post(_typeof._objectSpread2(_typeof._objectSpread2({
483
+ post(_typeof._objectSpread2(_typeof._objectSpread2(_typeof._objectSpread2({
429
484
  val: client.VAL_CANVAS_MESSAGE,
430
485
  type: "ready",
431
486
  draftMode: draftMode,
@@ -434,7 +489,16 @@ function ValCanvasBridge(_ref) {
434
489
  holds: _toConsumableArray(holds)
435
490
  } : {}), holdsVersions !== undefined && Object.keys(holdsVersions).length > 0 ? {
436
491
  holdsVersions: holdsVersions
437
- } : {}));
492
+ } : {}), {}, {
493
+ // What this bridge answers, so the Studio never waits on a request
494
+ // it would not: see `capabilities` in the protocol.
495
+ capabilities: _toConsumableArray(client.BRIDGE_CAPABILITIES),
496
+ document: DOCUMENT_ID,
497
+ bridge: {
498
+ "package": "@valbuild/tanstack",
499
+ version: version.VERSION
500
+ }
501
+ }));
438
502
  }, [post, draftMode, holds, holdsVersions]);
439
503
 
440
504
  /**
@@ -547,6 +611,22 @@ function ValCanvasBridge(_ref) {
547
611
  setPicking(message.picking);
548
612
  return;
549
613
  }
614
+ if (message.type === "textFields") {
615
+ // What starts an edit on a click, so as `editInline`: only from the
616
+ // frame's parent, when that is the Studio here.
617
+ if (event.source !== window.parent) return;
618
+ if (event.origin !== window.location.origin) return;
619
+ textFields.current = {
620
+ editing: message.editing,
621
+ editable: new Map(message.editable.map(function (candidate) {
622
+ return [candidate.path, candidate];
623
+ })),
624
+ empty: new Set(message.empty),
625
+ origin: event.origin
626
+ };
627
+ scan();
628
+ return;
629
+ }
550
630
  if (message.type === "pickElements") {
551
631
  var _message$color;
552
632
  setElementPicking({
@@ -579,15 +659,60 @@ function ValCanvasBridge(_ref) {
579
659
  window.parent.postMessage(readPageReply(message), asker);
580
660
  return;
581
661
  }
662
+ if (message.type === "readPageLog") {
663
+ // The assistant's `read_page_log`: what the page logged as going
664
+ // wrong. As `readPage`: only for the frame's parent, when that is
665
+ // the Studio here, and answered to it alone.
666
+ if (event.source !== window.parent) return;
667
+ var _asker = event.origin;
668
+ if (_asker !== window.location.origin) return;
669
+ window.parent.postMessage(readPageLogReply(message), _asker);
670
+ return;
671
+ }
672
+ if (message.type === "interact") {
673
+ // The assistant's `interact_page`: do something on the page and
674
+ // read it once it settled (`pageInteraction.ts`) -- a click or
675
+ // Enter/Space only once the person allowed it. As
676
+ // `readPage`: only for the frame's parent, when that is the Studio
677
+ // here, and answered to it alone.
678
+ if (event.source !== window.parent) return;
679
+ var _asker2 = event.origin;
680
+ if (_asker2 !== window.location.origin) return;
681
+ var requestId = message.requestId;
682
+ void client.interactWithPage(window, _typeof._objectSpread2(_typeof._objectSpread2(_typeof._objectSpread2(_typeof._objectSpread2(_typeof._objectSpread2({
683
+ action: message.action
684
+ }, message.maxItems !== undefined ? {
685
+ maxItems: message.maxItems
686
+ } : {}), message.timeoutMs !== undefined ? {
687
+ timeoutMs: message.timeoutMs
688
+ } : {}), message.logFrom !== undefined ? {
689
+ logFrom: message.logFrom
690
+ } : {}), message.approved !== undefined ? {
691
+ approved: message.approved
692
+ } : {}), {}, {
693
+ document: DOCUMENT_ID
694
+ }), pageLog()).then(function (outcome) {
695
+ var answer = {
696
+ val: client.VAL_CANVAS_MESSAGE,
697
+ type: "interacted",
698
+ requestId: requestId,
699
+ outcome: outcome,
700
+ // Which document answered: see `interacted` in the protocol.
701
+ document: DOCUMENT_ID
702
+ };
703
+ window.parent.postMessage(answer, _asker2);
704
+ });
705
+ return;
706
+ }
582
707
  if (message.type === "screenshotPage") {
583
708
  // The assistant's `screenshot_page`: a picture of the page, drawn
584
709
  // here. As `readPage`: only for the frame's parent, when that is the
585
710
  // Studio here, and answered to it alone.
586
711
  if (event.source !== window.parent) return;
587
- var _asker = event.origin;
588
- if (_asker !== window.location.origin) return;
712
+ var _asker3 = event.origin;
713
+ if (_asker3 !== window.location.origin) return;
589
714
  void screenshotReply(message).then(function (reply) {
590
- return window.parent.postMessage(reply, _asker);
715
+ return window.parent.postMessage(reply, _asker3);
591
716
  });
592
717
  return;
593
718
  }
@@ -638,6 +763,98 @@ function ValCanvasBridge(_ref) {
638
763
  }))();
639
764
  return;
640
765
  }
766
+ if (message.type === "stopInlineEdit") {
767
+ var _inlineEditing$curren2;
768
+ (_inlineEditing$curren2 = inlineEditing.current) === null || _inlineEditing$curren2 === void 0 || _inlineEditing$curren2.stop();
769
+ return;
770
+ }
771
+ if (message.type === "focusInlineEdit") {
772
+ var _inlineEditing$curren3;
773
+ (_inlineEditing$curren3 = inlineEditing.current) === null || _inlineEditing$curren3 === void 0 || _inlineEditing$curren3.focus();
774
+ return;
775
+ }
776
+ if (message.type === "applyInlineEdit") {
777
+ // What one of the Studio's controls made of the text being typed
778
+ // in. It replaces what is on the page, so as `editInline`: only
779
+ // from the frame's parent, when that is the Studio here.
780
+ if (event.source !== window.parent) return;
781
+ if (event.origin !== window.location.origin) return;
782
+ var editing = inlineEditing.current;
783
+ if (editing === null || !editing.isActive()) return;
784
+ if (editing.path !== message.path) return;
785
+ editing.apply(message.value, message.selection);
786
+ return;
787
+ }
788
+ if (message.type === "markInlineEdit") {
789
+ // Bold pressed with only a caret: for what is typed next. From the
790
+ // Studio only, as `applyInlineEdit`.
791
+ if (event.source !== window.parent) return;
792
+ if (event.origin !== window.location.origin) return;
793
+ var _editing = inlineEditing.current;
794
+ if (_editing === null || !_editing.isActive()) return;
795
+ if (_editing.path !== message.path) return;
796
+ _editing.mark(message.styles, message.selection);
797
+ return;
798
+ }
799
+ if (message.type === "editInline") {
800
+ var _held$release, _inlineEditing$curren4, _inlineEditing$curren5;
801
+ // A field's words go back as they are typed, unpublished ones
802
+ // included. As `readPage`: only for the frame's parent, when that
803
+ // is the Studio here, and answered to it alone.
804
+ if (event.source !== window.parent) return;
805
+ var _asker4 = event.origin;
806
+ if (_asker4 !== window.location.origin) return;
807
+ var reply = function reply(answer) {
808
+ return window.parent.postMessage(answer, _asker4);
809
+ };
810
+ var pick = lastPick.current;
811
+ lastPick.current = null;
812
+ var held = heldKeys.current;
813
+ heldKeys.current = null;
814
+ var keys = (_held$release = held === null || held === void 0 ? void 0 : held.release()) !== null && _held$release !== void 0 ? _held$release : [];
815
+ // The answer to a click from before the one that started the edit
816
+ // in progress, by itself: that click is what the person did last.
817
+ if (pick === null && startedOnClick.current && ((_inlineEditing$curren4 = inlineEditing.current) === null || _inlineEditing$curren4 === void 0 ? void 0 : _inlineEditing$curren4.isActive()) === true) {
818
+ reply({
819
+ val: client.VAL_CANVAS_MESSAGE,
820
+ type: "inlineEditUnavailable",
821
+ requestId: message.requestId
822
+ });
823
+ return;
824
+ }
825
+ // One edit at a time, and the element of the last one back as the
826
+ // page has it: it may be the very one asked for again.
827
+ (_inlineEditing$curren5 = inlineEditing.current) === null || _inlineEditing$curren5 === void 0 || _inlineEditing$curren5.release();
828
+ inlineEditing.current = null;
829
+ startedOnClick.current = false;
830
+ var started = startFirst(message.candidates, pick, {
831
+ color: selectionColor.current,
832
+ reply: reply
833
+ });
834
+ if (started !== null) {
835
+ inlineEditing.current = started.editing;
836
+ reply({
837
+ val: client.VAL_CANVAS_MESSAGE,
838
+ type: "inlineEditStarted",
839
+ requestId: message.requestId,
840
+ path: started.path
841
+ });
842
+ // What was typed while the Studio was being asked, now that
843
+ // there is somewhere for it to go: after `inlineEditStarted`,
844
+ // so the Studio is listening for what it types.
845
+ client.replayKeys(document, keys);
846
+ return;
847
+ }
848
+ // Nothing on the page shows one of them and nothing else: the
849
+ // Studio opens the field in its own column, and the keys pressed
850
+ // meanwhile are dropped, as on a page that is not being typed in.
851
+ reply({
852
+ val: client.VAL_CANVAS_MESSAGE,
853
+ type: "inlineEditUnavailable",
854
+ requestId: message.requestId
855
+ });
856
+ return;
857
+ }
641
858
  if (message.type === "theme") {
642
859
  setSelectionColors({
643
860
  selection: message.selection,
@@ -726,10 +943,17 @@ function ValCanvasBridge(_ref) {
726
943
  };
727
944
  }, [codeChanged, post]);
728
945
 
729
- // Where the page is, as it moves: a new build is opened there.
946
+ // The page's log, if the provider's module did not start it already.
947
+ React__default["default"].useEffect(function () {
948
+ pageLog();
949
+ }, []);
950
+
951
+ // Where the page is, as it moves: a new build is opened there. The log
952
+ // hears of it too, so a client-side navigation starts a new page in it.
730
953
  React__default["default"].useEffect(function () {
731
954
  return client.watchPageLocation(window, function (location) {
732
- return post(_typeof._objectSpread2({
955
+ pageLog().noteLocation();
956
+ post(_typeof._objectSpread2({
733
957
  val: client.VAL_CANVAS_MESSAGE,
734
958
  type: "location"
735
959
  }, location));
@@ -746,18 +970,85 @@ function ValCanvasBridge(_ref) {
746
970
  */
747
971
  React__default["default"].useEffect(function () {
748
972
  var onClick = function onClick(event) {
749
- if (!pickingRef.current) return;
973
+ var _heldKeys$current2;
750
974
  var target = event.target;
751
975
  if (!(target instanceof Element)) return;
976
+ // A click in the field being typed in places the caret, and that is
977
+ // all it does: it is neither a pick nor a click on the link or button
978
+ // the text happens to be in. (The caret is the mousedown's, so
979
+ // cancelling the click leaves it where it was put.)
980
+ var editing = inlineEditing.current;
981
+ if (editing !== null && editing.isActive() && editing.contains(target)) {
982
+ event.preventDefault();
983
+ event.stopPropagation();
984
+ return;
985
+ }
986
+ if (!pickingRef.current) return;
752
987
  var tagged = target.closest("[data-val-path]");
753
988
  var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
754
- if (!attribute) return;
989
+ if (!tagged || !attribute) return;
755
990
  event.preventDefault();
756
991
  event.stopPropagation();
992
+ var paths = core.Internal.splitJoinedSourcePaths(attribute);
993
+ var pick = {
994
+ element: tagged,
995
+ x: event.clientX,
996
+ y: event.clientY
997
+ };
998
+ (_heldKeys$current2 = heldKeys.current) === null || _heldKeys$current2 === void 0 || _heldKeys$current2.release();
999
+ heldKeys.current = null;
1000
+ /*
1001
+ * Select & edit, and the Studio has said which of this element's
1002
+ * fields are texts and what they hold: the edit starts HERE, in the
1003
+ * click, rather than a round trip across the frame later. Keys typed
1004
+ * straight after the click then go into the text -- in that round
1005
+ * trip they went to the page's body, which drops them -- and a phone
1006
+ * opens its keyboard, which it does only for a focus given in the tap.
1007
+ * Which element shows a field is still decided as `editInline` decides
1008
+ * it (`canEditInline`), from the values the Studio sent.
1009
+ */
1010
+ var known = textFields.current;
1011
+ var offered = known !== null && known.editing ? paths.flatMap(function (path) {
1012
+ var _known$editable$get;
1013
+ return (_known$editable$get = known.editable.get(path)) !== null && _known$editable$get !== void 0 ? _known$editable$get : [];
1014
+ }) : [];
1015
+ if (known !== null && offered.length > 0) {
1016
+ var _inlineEditing$curren6;
1017
+ var reply = function reply(answer) {
1018
+ return window.parent.postMessage(answer, known.origin);
1019
+ };
1020
+ (_inlineEditing$curren6 = inlineEditing.current) === null || _inlineEditing$curren6 === void 0 || _inlineEditing$curren6.release();
1021
+ inlineEditing.current = null;
1022
+ startedOnClick.current = false;
1023
+ var started = startFirst(offered, pick, {
1024
+ color: selectionColor.current,
1025
+ reply: reply
1026
+ });
1027
+ if (started !== null) {
1028
+ inlineEditing.current = started.editing;
1029
+ startedOnClick.current = true;
1030
+ lastPick.current = null;
1031
+ reply({
1032
+ val: client.VAL_CANVAS_MESSAGE,
1033
+ type: "inlineEditStarted",
1034
+ requestId: null,
1035
+ path: started.path
1036
+ });
1037
+ return;
1038
+ }
1039
+ /*
1040
+ * A text, but not as the Studio last said: its value changed since
1041
+ * (an edit a moment ago, still on its way). The Studio is asked, as
1042
+ * for any pick, and the keys pressed until it answers are held
1043
+ * rather than lost.
1044
+ */
1045
+ heldKeys.current = client.holdKeys(window);
1046
+ }
1047
+ lastPick.current = pick;
757
1048
  post({
758
1049
  val: client.VAL_CANVAS_MESSAGE,
759
1050
  type: "clicked",
760
- paths: core.Internal.splitJoinedSourcePaths(attribute)
1051
+ paths: paths
761
1052
  });
762
1053
  };
763
1054
  document.addEventListener("click", onClick, {
@@ -770,6 +1061,17 @@ function ValCanvasBridge(_ref) {
770
1061
  };
771
1062
  }, [post]);
772
1063
 
1064
+ // Select off: an emptied text has its room taken away, and keys held for
1065
+ // an answer to a pick are dropped. Select on: it has its room again.
1066
+ React__default["default"].useEffect(function () {
1067
+ if (!picking) {
1068
+ var _heldKeys$current3;
1069
+ (_heldKeys$current3 = heldKeys.current) === null || _heldKeys$current3 === void 0 || _heldKeys$current3.release();
1070
+ heldKeys.current = null;
1071
+ }
1072
+ scan();
1073
+ }, [picking, scan]);
1074
+
773
1075
  // Esc while picking fields: the key goes to the page, which has the focus
774
1076
  // once it has been clicked, so the studio hears of it only from here.
775
1077
  React__default["default"].useEffect(function () {
@@ -977,7 +1279,11 @@ function ValCanvasBridge(_ref) {
977
1279
  // CSS string. A path contains quotes (`?p="/"`) and would otherwise
978
1280
  // close the selector early.
979
1281
  dangerouslySetInnerHTML: {
980
- __html: [picking ? "[data-val-path] { outline: 1px solid ".concat(selectionColors.selectionSoft, "; outline-offset: 1px; cursor: pointer; }\n[data-val-path]:hover { outline: 2px solid ").concat(selectionColors.selection, "; }") : "", highlighted ? highlightRule(highlighted, selectionColors.selection) : ""].filter(Boolean).join("\n")
1282
+ __html: [picking ? "[data-val-path] { outline: 1px solid ".concat(selectionColors.selectionSoft, "; outline-offset: 1px; cursor: pointer; }\n[data-val-path]:hover { outline: 2px solid ").concat(selectionColors.selection, "; }") : "",
1283
+ // The one rule here that moves the page, and only while Select is
1284
+ // on: an emptied text's line of room, without which it cannot be
1285
+ // pointed at. See `emptyTextFields.ts` for why, and how narrowly.
1286
+ picking ? client.EMPTY_TEXT_RULES : "", highlighted ? highlightRule(highlighted, selectionColors.selection) : ""].filter(Boolean).join("\n")
981
1287
  }
982
1288
  });
983
1289
  }
@@ -1074,28 +1380,118 @@ function isScrollable(el) {
1074
1380
  };
1075
1381
  return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
1076
1382
  }
1383
+ var NO_PATHS = new Set();
1384
+
1385
+ /**
1386
+ * Start editing the first of `candidates` an element on the page shows and
1387
+ * nothing else: the picked element when it carries the candidate's path,
1388
+ * else the first element that does. `null` when none can be.
1389
+ *
1390
+ * What `editInline` does, and what a click does by itself when the Studio has
1391
+ * said ahead of it what the element's texts hold (`textFields`): one way to
1392
+ * start, whichever asked.
1393
+ */
1394
+ function startFirst(candidates, pick, options) {
1395
+ var reply = options.reply;
1396
+ var _iterator = _typeof._createForOfIteratorHelper(candidates),
1397
+ _step;
1398
+ try {
1399
+ var _loop = function _loop() {
1400
+ var candidate = _step.value;
1401
+ var picked = pick !== null && pick.element.isConnected && pathOn(pick.element, candidate.path) !== null ? pick.element : null;
1402
+ var element = picked !== null && picked !== void 0 ? picked : findByPath(candidate.path);
1403
+ if (element === null) return 0; // continue
1404
+ var path = pathOn(element, candidate.path);
1405
+ if (path === null) return 0; // continue
1406
+ var editing = client.startInlineEditing(element, candidate, {
1407
+ // Where the click was, when it was on this element.
1408
+ at: picked !== null && pick !== null ? {
1409
+ x: pick.x,
1410
+ y: pick.y
1411
+ } : null,
1412
+ color: options.color,
1413
+ onChange: function onChange(value) {
1414
+ return reply({
1415
+ val: client.VAL_CANVAS_MESSAGE,
1416
+ type: "inlineEdit",
1417
+ path: path,
1418
+ value: value
1419
+ });
1420
+ },
1421
+ onEnd: function onEnd() {
1422
+ return reply({
1423
+ val: client.VAL_CANVAS_MESSAGE,
1424
+ type: "inlineEditEnded",
1425
+ path: path
1426
+ });
1427
+ },
1428
+ onSelection: function onSelection(selection, rect, caret) {
1429
+ return reply({
1430
+ val: client.VAL_CANVAS_MESSAGE,
1431
+ type: "inlineEditSelection",
1432
+ path: path,
1433
+ selection: selection,
1434
+ rect: rect,
1435
+ caret: caret
1436
+ });
1437
+ }
1438
+ });
1439
+ if (editing !== null) return {
1440
+ v: {
1441
+ editing: editing,
1442
+ path: path
1443
+ }
1444
+ };
1445
+ },
1446
+ _ret;
1447
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1448
+ _ret = _loop();
1449
+ if (_ret === 0) continue;
1450
+ if (_ret) return _ret.v;
1451
+ }
1452
+ } catch (err) {
1453
+ _iterator.e(err);
1454
+ } finally {
1455
+ _iterator.f();
1456
+ }
1457
+ return null;
1458
+ }
1077
1459
  function findByPath(path) {
1078
1460
  var elements = document.querySelectorAll("[data-val-path]");
1079
1461
  for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
1080
1462
  var el = _Array$from[_i];
1081
- var attribute = el.getAttribute("data-val-path");
1082
- if (!attribute) continue;
1083
- // Compared as strings: the split returns branded `SourcePath`s and what
1084
- // came back over `postMessage` is a plain string, which is the same value.
1085
- if (core.Internal.splitJoinedSourcePaths(attribute).some(function (candidate) {
1086
- return candidate === path;
1087
- })) {
1088
- return el;
1089
- }
1463
+ if (pathOn(el, path) !== null) return el;
1090
1464
  }
1091
1465
  return null;
1092
1466
  }
1093
1467
 
1468
+ /**
1469
+ * `path` as `element` carries it, or null when it does not.
1470
+ *
1471
+ * Compared as strings: the split returns branded `SourcePath`s and what came
1472
+ * back over `postMessage` is a plain string, which is the same value. What is
1473
+ * returned is the element's own, so it is a `SourcePath` without anyone
1474
+ * having to say so.
1475
+ */
1476
+ function pathOn(element, path) {
1477
+ var _Internal$splitJoined;
1478
+ var attribute = element.getAttribute("data-val-path");
1479
+ if (!attribute) return null;
1480
+ return (_Internal$splitJoined = core.Internal.splitJoinedSourcePaths(attribute).find(function (candidate) {
1481
+ return candidate === path;
1482
+ })) !== null && _Internal$splitJoined !== void 0 ? _Internal$splitJoined : null;
1483
+ }
1484
+
1094
1485
  /** What `screenshotPage` answers: the picture, or why it could not be taken. */
1095
1486
  function screenshotReply(_x) {
1096
1487
  return _screenshotReply.apply(this, arguments);
1097
1488
  }
1098
- /** What `readPage` answers: the page read, or why it could not be. */
1489
+ /**
1490
+ * The page's log (`pageLog.ts`). Started when the provider's module was
1491
+ * evaluated in the canvas, before hydration; started here, as late as the
1492
+ * bridge mounts, only if that did not happen -- a document that was not the
1493
+ * canvas when the provider loaded (see `isValCanvasFrame`).
1494
+ */
1099
1495
  function _screenshotReply() {
1100
1496
  _screenshotReply = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee2(message) {
1101
1497
  var _t2, _t3, _t4, _t5;
@@ -1137,17 +1533,49 @@ function _screenshotReply() {
1137
1533
  }));
1138
1534
  return _screenshotReply.apply(this, arguments);
1139
1535
  }
1536
+ function pageLog() {
1537
+ return client.installPageLog(window);
1538
+ }
1539
+
1540
+ /** What `readPageLog` answers: the page's log, or why it could not be read. */
1541
+ function readPageLogReply(message) {
1542
+ try {
1543
+ return {
1544
+ val: client.VAL_CANVAS_MESSAGE,
1545
+ type: "pageLogRead",
1546
+ requestId: message.requestId,
1547
+ log: pageLog().read(_typeof._objectSpread2(_typeof._objectSpread2({}, message.sinceNavigation !== undefined ? {
1548
+ sinceNavigation: message.sinceNavigation
1549
+ } : {}), message.levels !== undefined ? {
1550
+ levels: message.levels
1551
+ } : {}))
1552
+ };
1553
+ } catch (error) {
1554
+ return {
1555
+ val: client.VAL_CANVAS_MESSAGE,
1556
+ type: "pageLogRead",
1557
+ requestId: message.requestId,
1558
+ log: null,
1559
+ error: error instanceof Error ? error.message : String(error)
1560
+ };
1561
+ }
1562
+ }
1563
+
1564
+ /** What `readPage` answers: the page read, or why it could not be. */
1140
1565
  function readPageReply(message) {
1141
1566
  try {
1142
1567
  return {
1143
1568
  val: client.VAL_CANVAS_MESSAGE,
1144
1569
  type: "pageRead",
1145
1570
  requestId: message.requestId,
1146
- snapshot: client.readPageSnapshot(document, _typeof._objectSpread2(_typeof._objectSpread2({}, message.selector !== undefined ? {
1571
+ snapshot: _typeof._objectSpread2(_typeof._objectSpread2({}, client.readPageSnapshot(document, _typeof._objectSpread2(_typeof._objectSpread2({}, message.selector !== undefined ? {
1147
1572
  selector: message.selector
1148
1573
  } : {}), message.maxItems !== undefined ? {
1149
1574
  maxItems: message.maxItems
1150
- } : {}))
1575
+ } : {}))), {}, {
1576
+ // So the assistant notices the page threw without asking.
1577
+ log: pageLog().counts()
1578
+ })
1151
1579
  };
1152
1580
  } catch (error) {
1153
1581
  return {
@@ -1316,6 +1744,19 @@ function PlatformAnalytics(_ref) {
1316
1744
  });
1317
1745
  }
1318
1746
 
1747
+ client.installPageLogInCanvasFrame(function () {
1748
+ return hasValEnableCookie(document.cookie);
1749
+ });
1750
+
1751
+ /**
1752
+ * Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
1753
+ */
1754
+ /**
1755
+ * How often `/draft/stat` is asked when nothing is in progress.
1756
+ *
1757
+ * Draft mode changes when someone toggles it, which the handshake below already
1758
+ * covers — so this is only there to notice it being changed somewhere else.
1759
+ */
1319
1760
  var DRAFT_IDLE_POLL_MS = 20000;
1320
1761
 
1321
1762
  /**