@valbuild/next 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.
Files changed (24) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/ValCanvasBridge-063ad333.cjs.js +7 -0
  3. package/dist/{ValCanvasBridge-50bf5366.cjs.prod.js → ValCanvasBridge-063ad333.cjs.prod.js} +453 -23
  4. package/dist/{ValCanvasBridge-cf8d7967.esm.js → ValCanvasBridge-719e6efe.esm.js} +454 -24
  5. package/dist/{ValCanvasBridge-fc46ab88.cjs.dev.js → ValCanvasBridge-9b2df334.cjs.dev.js} +453 -23
  6. package/dist/{ValNextProvider-b4eae85e.esm.js → ValNextProvider-27242758.esm.js} +15 -2
  7. package/dist/{ValNextProvider-5e29689e.cjs.dev.js → ValNextProvider-4838fed0.cjs.dev.js} +14 -1
  8. package/dist/ValNextProvider-9343dc1e.cjs.js +7 -0
  9. package/dist/{ValNextProvider-06854ec0.cjs.prod.js → ValNextProvider-9343dc1e.cjs.prod.js} +14 -1
  10. package/dist/valbuild-next.cjs.dev.js +2 -2
  11. package/dist/valbuild-next.cjs.prod.js +2 -2
  12. package/dist/valbuild-next.esm.js +2 -2
  13. package/dist/{version-a7fe5cf9.cjs.prod.js → version-4d44d9cd.cjs.prod.js} +1 -1
  14. package/dist/{version-ac0839be.cjs.dev.js → version-93ae5f54.cjs.dev.js} +1 -1
  15. package/dist/{version-32b03e4b.esm.js → version-9adeab58.esm.js} +1 -1
  16. package/package.json +7 -7
  17. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +1 -1
  18. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +1 -1
  19. package/rsc/dist/valbuild-next-rsc.esm.js +1 -1
  20. package/server/dist/valbuild-next-server.cjs.dev.js +1 -1
  21. package/server/dist/valbuild-next-server.cjs.prod.js +1 -1
  22. package/server/dist/valbuild-next-server.esm.js +1 -1
  23. package/dist/ValCanvasBridge-50bf5366.cjs.js +0 -7
  24. package/dist/ValNextProvider-06854ec0.cjs.js +0 -7
@@ -3,6 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
+ var createForOfIteratorHelper = require('./createForOfIteratorHelper-9c6aa3c7.cjs.dev.js');
6
7
  var asyncToGenerator = require('./asyncToGenerator-c3823d62.cjs.dev.js');
7
8
  var unsupportedIterableToArray = require('./unsupportedIterableToArray-20a9209f.cjs.dev.js');
8
9
  var objectSpread2 = require('./objectSpread2-58726b14.cjs.dev.js');
@@ -10,6 +11,7 @@ var slicedToArray = require('./slicedToArray-ed812733.cjs.dev.js');
10
11
  var React = require('react');
11
12
  var core = require('@valbuild/core');
12
13
  var client = require('@valbuild/shared/client');
14
+ var version = require('./version-93ae5f54.cjs.dev.js');
13
15
  var jsxRuntime = require('react/jsx-runtime');
14
16
 
15
17
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -46,6 +48,13 @@ var DEFAULT_SELECTION = {
46
48
  */
47
49
  var RESCAN_INTERVAL_MS = 5000;
48
50
 
51
+ /**
52
+ * This document, among the ones the frame loads: sent with every `ready`
53
+ * (see `document` there). Made when the module is evaluated, which is once
54
+ * per document. Not `crypto.randomUUID`, which an insecure context lacks.
55
+ */
56
+ var DOCUMENT_ID = "".concat(Date.now().toString(36), "-").concat(Math.random().toString(36).slice(2));
57
+
49
58
  /**
50
59
  * The page's half of the canvas protocol.
51
60
  *
@@ -110,6 +119,50 @@ function ValCanvasBridge(_ref) {
110
119
  return (_stopRestoring$curren = stopRestoring.current) === null || _stopRestoring$curren === void 0 ? void 0 : _stopRestoring$curren.call(stopRestoring);
111
120
  };
112
121
  }, []);
122
+ /**
123
+ * The field being edited on the page itself (`editInline`), or the last
124
+ * one that was, while its copy waits for the page to catch up. See
125
+ * `inlineEditing.ts` in `@valbuild/shared`, which both bindings run.
126
+ */
127
+ var inlineEditing = React__default["default"].useRef(null);
128
+ React__default["default"].useEffect(function () {
129
+ return function () {
130
+ var _inlineEditing$curren;
131
+ return (_inlineEditing$curren = inlineEditing.current) === null || _inlineEditing$curren === void 0 ? void 0 : _inlineEditing$curren.release();
132
+ };
133
+ }, []);
134
+ /**
135
+ * The last pick: the element and where on it. `editInline` is the Studio's
136
+ * answer to a `clicked`, and the caret belongs where that click was.
137
+ */
138
+ var lastPick = React__default["default"].useRef(null);
139
+ /**
140
+ * The page's texts as the Studio last said (`textFields`), and the origin
141
+ * that said it, which is the only one an edit started from them answers.
142
+ * `null` until it says: a Studio that predates it never does, and every
143
+ * click then asks, as before.
144
+ */
145
+ var textFields = React__default["default"].useRef(null);
146
+ /**
147
+ * Whether the edit in progress was started here, in a click, rather than
148
+ * by `editInline`: an `editInline` that arrives after it answers a click
149
+ * from before it, and must not take the caret away.
150
+ */
151
+ var startedOnClick = React__default["default"].useRef(false);
152
+ /**
153
+ * The keys pressed since a click the Studio was asked about, until it
154
+ * answers: see `inlineEditKeys.ts`.
155
+ */
156
+ var heldKeys = React__default["default"].useRef(null);
157
+ React__default["default"].useEffect(function () {
158
+ return function () {
159
+ var _heldKeys$current;
160
+ (_heldKeys$current = heldKeys.current) === null || _heldKeys$current === void 0 || _heldKeys$current.release();
161
+ };
162
+ }, []);
163
+ // Read when an edit starts, long after the render that set it.
164
+ var selectionColor = React__default["default"].useRef(selectionColors.selection);
165
+ selectionColor.current = selectionColors.selection;
113
166
  var post = React__default["default"].useCallback(function (message) {
114
167
  // `*` as the target origin: the studio and the page share an origin today,
115
168
  // but the frame does not know the parent's origin for certain and naming
@@ -131,6 +184,10 @@ function ValCanvasBridge(_ref) {
131
184
 
132
185
  /** Every element Val tagged, with where it is on the page. */
133
186
  var scan = React__default["default"].useCallback(function () {
187
+ var _textFields$current$e, _textFields$current;
188
+ // Before measuring: an emptied text measures with the room it is given
189
+ // while Select is on, so the Studio's outline of it has a size too.
190
+ 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);
134
191
  var elements = [];
135
192
  var scrollX = window.scrollX;
136
193
  var scrollY = window.scrollY;
@@ -208,7 +265,7 @@ function ValCanvasBridge(_ref) {
208
265
 
209
266
  // Announce the frame, and say whether it is actually showing draft content.
210
267
  React__default["default"].useEffect(function () {
211
- post(objectSpread2._objectSpread2(objectSpread2._objectSpread2({
268
+ post(objectSpread2._objectSpread2(objectSpread2._objectSpread2(objectSpread2._objectSpread2({
212
269
  val: client.VAL_CANVAS_MESSAGE,
213
270
  type: "ready",
214
271
  draftMode: draftMode,
@@ -217,7 +274,16 @@ function ValCanvasBridge(_ref) {
217
274
  holds: _toConsumableArray(holds)
218
275
  } : {}), holdsVersions !== undefined && Object.keys(holdsVersions).length > 0 ? {
219
276
  holdsVersions: holdsVersions
220
- } : {}));
277
+ } : {}), {}, {
278
+ // What this bridge answers, so the Studio never waits on a request
279
+ // it would not: see `capabilities` in the protocol.
280
+ capabilities: _toConsumableArray(client.BRIDGE_CAPABILITIES),
281
+ document: DOCUMENT_ID,
282
+ bridge: {
283
+ "package": "@valbuild/next",
284
+ version: version.VERSION
285
+ }
286
+ }));
221
287
  }, [post, draftMode, holds, holdsVersions]);
222
288
 
223
289
  /**
@@ -330,6 +396,22 @@ function ValCanvasBridge(_ref) {
330
396
  setPicking(message.picking);
331
397
  return;
332
398
  }
399
+ if (message.type === "textFields") {
400
+ // What starts an edit on a click, so as `editInline`: only from the
401
+ // frame's parent, when that is the Studio here.
402
+ if (event.source !== window.parent) return;
403
+ if (event.origin !== window.location.origin) return;
404
+ textFields.current = {
405
+ editing: message.editing,
406
+ editable: new Map(message.editable.map(function (candidate) {
407
+ return [candidate.path, candidate];
408
+ })),
409
+ empty: new Set(message.empty),
410
+ origin: event.origin
411
+ };
412
+ scan();
413
+ return;
414
+ }
333
415
  if (message.type === "pickElements") {
334
416
  var _message$color;
335
417
  setElementPicking({
@@ -362,15 +444,60 @@ function ValCanvasBridge(_ref) {
362
444
  window.parent.postMessage(readPageReply(message), asker);
363
445
  return;
364
446
  }
447
+ if (message.type === "readPageLog") {
448
+ // The assistant's `read_page_log`: what the page logged as going
449
+ // wrong. As `readPage`: only for the frame's parent, when that is
450
+ // the Studio here, and answered to it alone.
451
+ if (event.source !== window.parent) return;
452
+ var _asker = event.origin;
453
+ if (_asker !== window.location.origin) return;
454
+ window.parent.postMessage(readPageLogReply(message), _asker);
455
+ return;
456
+ }
457
+ if (message.type === "interact") {
458
+ // The assistant's `interact_page`: do something on the page and
459
+ // read it once it settled (`pageInteraction.ts`) -- a click or
460
+ // Enter/Space only once the person allowed it. As
461
+ // `readPage`: only for the frame's parent, when that is the Studio
462
+ // here, and answered to it alone.
463
+ if (event.source !== window.parent) return;
464
+ var _asker2 = event.origin;
465
+ if (_asker2 !== window.location.origin) return;
466
+ var requestId = message.requestId;
467
+ void client.interactWithPage(window, objectSpread2._objectSpread2(objectSpread2._objectSpread2(objectSpread2._objectSpread2(objectSpread2._objectSpread2(objectSpread2._objectSpread2({
468
+ action: message.action
469
+ }, message.maxItems !== undefined ? {
470
+ maxItems: message.maxItems
471
+ } : {}), message.timeoutMs !== undefined ? {
472
+ timeoutMs: message.timeoutMs
473
+ } : {}), message.logFrom !== undefined ? {
474
+ logFrom: message.logFrom
475
+ } : {}), message.approved !== undefined ? {
476
+ approved: message.approved
477
+ } : {}), {}, {
478
+ document: DOCUMENT_ID
479
+ }), pageLog()).then(function (outcome) {
480
+ var answer = {
481
+ val: client.VAL_CANVAS_MESSAGE,
482
+ type: "interacted",
483
+ requestId: requestId,
484
+ outcome: outcome,
485
+ // Which document answered: see `interacted` in the protocol.
486
+ document: DOCUMENT_ID
487
+ };
488
+ window.parent.postMessage(answer, _asker2);
489
+ });
490
+ return;
491
+ }
365
492
  if (message.type === "screenshotPage") {
366
493
  // The assistant's `screenshot_page`: a picture of the page, drawn
367
494
  // here. As `readPage`: only for the frame's parent, when that is the
368
495
  // Studio here, and answered to it alone.
369
496
  if (event.source !== window.parent) return;
370
- var _asker = event.origin;
371
- if (_asker !== window.location.origin) return;
497
+ var _asker3 = event.origin;
498
+ if (_asker3 !== window.location.origin) return;
372
499
  void screenshotReply(message).then(function (reply) {
373
- return window.parent.postMessage(reply, _asker);
500
+ return window.parent.postMessage(reply, _asker3);
374
501
  });
375
502
  return;
376
503
  }
@@ -421,6 +548,98 @@ function ValCanvasBridge(_ref) {
421
548
  }))();
422
549
  return;
423
550
  }
551
+ if (message.type === "stopInlineEdit") {
552
+ var _inlineEditing$curren2;
553
+ (_inlineEditing$curren2 = inlineEditing.current) === null || _inlineEditing$curren2 === void 0 || _inlineEditing$curren2.stop();
554
+ return;
555
+ }
556
+ if (message.type === "focusInlineEdit") {
557
+ var _inlineEditing$curren3;
558
+ (_inlineEditing$curren3 = inlineEditing.current) === null || _inlineEditing$curren3 === void 0 || _inlineEditing$curren3.focus();
559
+ return;
560
+ }
561
+ if (message.type === "applyInlineEdit") {
562
+ // What one of the Studio's controls made of the text being typed
563
+ // in. It replaces what is on the page, so as `editInline`: only
564
+ // from the frame's parent, when that is the Studio here.
565
+ if (event.source !== window.parent) return;
566
+ if (event.origin !== window.location.origin) return;
567
+ var editing = inlineEditing.current;
568
+ if (editing === null || !editing.isActive()) return;
569
+ if (editing.path !== message.path) return;
570
+ editing.apply(message.value, message.selection);
571
+ return;
572
+ }
573
+ if (message.type === "markInlineEdit") {
574
+ // Bold pressed with only a caret: for what is typed next. From the
575
+ // Studio only, as `applyInlineEdit`.
576
+ if (event.source !== window.parent) return;
577
+ if (event.origin !== window.location.origin) return;
578
+ var _editing = inlineEditing.current;
579
+ if (_editing === null || !_editing.isActive()) return;
580
+ if (_editing.path !== message.path) return;
581
+ _editing.mark(message.styles, message.selection);
582
+ return;
583
+ }
584
+ if (message.type === "editInline") {
585
+ var _held$release, _inlineEditing$curren4, _inlineEditing$curren5;
586
+ // A field's words go back as they are typed, unpublished ones
587
+ // included. As `readPage`: only for the frame's parent, when that
588
+ // is the Studio here, and answered to it alone.
589
+ if (event.source !== window.parent) return;
590
+ var _asker4 = event.origin;
591
+ if (_asker4 !== window.location.origin) return;
592
+ var reply = function reply(answer) {
593
+ return window.parent.postMessage(answer, _asker4);
594
+ };
595
+ var pick = lastPick.current;
596
+ lastPick.current = null;
597
+ var held = heldKeys.current;
598
+ heldKeys.current = null;
599
+ var keys = (_held$release = held === null || held === void 0 ? void 0 : held.release()) !== null && _held$release !== void 0 ? _held$release : [];
600
+ // The answer to a click from before the one that started the edit
601
+ // in progress, by itself: that click is what the person did last.
602
+ if (pick === null && startedOnClick.current && ((_inlineEditing$curren4 = inlineEditing.current) === null || _inlineEditing$curren4 === void 0 ? void 0 : _inlineEditing$curren4.isActive()) === true) {
603
+ reply({
604
+ val: client.VAL_CANVAS_MESSAGE,
605
+ type: "inlineEditUnavailable",
606
+ requestId: message.requestId
607
+ });
608
+ return;
609
+ }
610
+ // One edit at a time, and the element of the last one back as the
611
+ // page has it: it may be the very one asked for again.
612
+ (_inlineEditing$curren5 = inlineEditing.current) === null || _inlineEditing$curren5 === void 0 || _inlineEditing$curren5.release();
613
+ inlineEditing.current = null;
614
+ startedOnClick.current = false;
615
+ var started = startFirst(message.candidates, pick, {
616
+ color: selectionColor.current,
617
+ reply: reply
618
+ });
619
+ if (started !== null) {
620
+ inlineEditing.current = started.editing;
621
+ reply({
622
+ val: client.VAL_CANVAS_MESSAGE,
623
+ type: "inlineEditStarted",
624
+ requestId: message.requestId,
625
+ path: started.path
626
+ });
627
+ // What was typed while the Studio was being asked, now that
628
+ // there is somewhere for it to go: after `inlineEditStarted`,
629
+ // so the Studio is listening for what it types.
630
+ client.replayKeys(document, keys);
631
+ return;
632
+ }
633
+ // Nothing on the page shows one of them and nothing else: the
634
+ // Studio opens the field in its own column, and the keys pressed
635
+ // meanwhile are dropped, as on a page that is not being typed in.
636
+ reply({
637
+ val: client.VAL_CANVAS_MESSAGE,
638
+ type: "inlineEditUnavailable",
639
+ requestId: message.requestId
640
+ });
641
+ return;
642
+ }
424
643
  if (message.type === "theme") {
425
644
  setSelectionColors({
426
645
  selection: message.selection,
@@ -509,10 +728,17 @@ function ValCanvasBridge(_ref) {
509
728
  };
510
729
  }, [codeChanged, post]);
511
730
 
512
- // Where the page is, as it moves: a new build is opened there.
731
+ // The page's log, if the provider's module did not start it already.
732
+ React__default["default"].useEffect(function () {
733
+ pageLog();
734
+ }, []);
735
+
736
+ // Where the page is, as it moves: a new build is opened there. The log
737
+ // hears of it too, so a client-side navigation starts a new page in it.
513
738
  React__default["default"].useEffect(function () {
514
739
  return client.watchPageLocation(window, function (location) {
515
- return post(objectSpread2._objectSpread2({
740
+ pageLog().noteLocation();
741
+ post(objectSpread2._objectSpread2({
516
742
  val: client.VAL_CANVAS_MESSAGE,
517
743
  type: "location"
518
744
  }, location));
@@ -529,18 +755,85 @@ function ValCanvasBridge(_ref) {
529
755
  */
530
756
  React__default["default"].useEffect(function () {
531
757
  var onClick = function onClick(event) {
532
- if (!pickingRef.current) return;
758
+ var _heldKeys$current2;
533
759
  var target = event.target;
534
760
  if (!(target instanceof Element)) return;
761
+ // A click in the field being typed in places the caret, and that is
762
+ // all it does: it is neither a pick nor a click on the link or button
763
+ // the text happens to be in. (The caret is the mousedown's, so
764
+ // cancelling the click leaves it where it was put.)
765
+ var editing = inlineEditing.current;
766
+ if (editing !== null && editing.isActive() && editing.contains(target)) {
767
+ event.preventDefault();
768
+ event.stopPropagation();
769
+ return;
770
+ }
771
+ if (!pickingRef.current) return;
535
772
  var tagged = target.closest("[data-val-path]");
536
773
  var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
537
- if (!attribute) return;
774
+ if (!tagged || !attribute) return;
538
775
  event.preventDefault();
539
776
  event.stopPropagation();
777
+ var paths = core.Internal.splitJoinedSourcePaths(attribute);
778
+ var pick = {
779
+ element: tagged,
780
+ x: event.clientX,
781
+ y: event.clientY
782
+ };
783
+ (_heldKeys$current2 = heldKeys.current) === null || _heldKeys$current2 === void 0 || _heldKeys$current2.release();
784
+ heldKeys.current = null;
785
+ /*
786
+ * Select & edit, and the Studio has said which of this element's
787
+ * fields are texts and what they hold: the edit starts HERE, in the
788
+ * click, rather than a round trip across the frame later. Keys typed
789
+ * straight after the click then go into the text -- in that round
790
+ * trip they went to the page's body, which drops them -- and a phone
791
+ * opens its keyboard, which it does only for a focus given in the tap.
792
+ * Which element shows a field is still decided as `editInline` decides
793
+ * it (`canEditInline`), from the values the Studio sent.
794
+ */
795
+ var known = textFields.current;
796
+ var offered = known !== null && known.editing ? paths.flatMap(function (path) {
797
+ var _known$editable$get;
798
+ return (_known$editable$get = known.editable.get(path)) !== null && _known$editable$get !== void 0 ? _known$editable$get : [];
799
+ }) : [];
800
+ if (known !== null && offered.length > 0) {
801
+ var _inlineEditing$curren6;
802
+ var reply = function reply(answer) {
803
+ return window.parent.postMessage(answer, known.origin);
804
+ };
805
+ (_inlineEditing$curren6 = inlineEditing.current) === null || _inlineEditing$curren6 === void 0 || _inlineEditing$curren6.release();
806
+ inlineEditing.current = null;
807
+ startedOnClick.current = false;
808
+ var started = startFirst(offered, pick, {
809
+ color: selectionColor.current,
810
+ reply: reply
811
+ });
812
+ if (started !== null) {
813
+ inlineEditing.current = started.editing;
814
+ startedOnClick.current = true;
815
+ lastPick.current = null;
816
+ reply({
817
+ val: client.VAL_CANVAS_MESSAGE,
818
+ type: "inlineEditStarted",
819
+ requestId: null,
820
+ path: started.path
821
+ });
822
+ return;
823
+ }
824
+ /*
825
+ * A text, but not as the Studio last said: its value changed since
826
+ * (an edit a moment ago, still on its way). The Studio is asked, as
827
+ * for any pick, and the keys pressed until it answers are held
828
+ * rather than lost.
829
+ */
830
+ heldKeys.current = client.holdKeys(window);
831
+ }
832
+ lastPick.current = pick;
540
833
  post({
541
834
  val: client.VAL_CANVAS_MESSAGE,
542
835
  type: "clicked",
543
- paths: core.Internal.splitJoinedSourcePaths(attribute)
836
+ paths: paths
544
837
  });
545
838
  };
546
839
  document.addEventListener("click", onClick, {
@@ -553,6 +846,17 @@ function ValCanvasBridge(_ref) {
553
846
  };
554
847
  }, [post]);
555
848
 
849
+ // Select off: an emptied text has its room taken away, and keys held for
850
+ // an answer to a pick are dropped. Select on: it has its room again.
851
+ React__default["default"].useEffect(function () {
852
+ if (!picking) {
853
+ var _heldKeys$current3;
854
+ (_heldKeys$current3 = heldKeys.current) === null || _heldKeys$current3 === void 0 || _heldKeys$current3.release();
855
+ heldKeys.current = null;
856
+ }
857
+ scan();
858
+ }, [picking, scan]);
859
+
556
860
  // Esc while picking fields: the key goes to the page, which has the focus
557
861
  // once it has been clicked, so the studio hears of it only from here.
558
862
  React__default["default"].useEffect(function () {
@@ -760,7 +1064,11 @@ function ValCanvasBridge(_ref) {
760
1064
  // CSS string. A path contains quotes (`?p="/"`) and would otherwise
761
1065
  // close the selector early.
762
1066
  dangerouslySetInnerHTML: {
763
- __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")
1067
+ __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, "; }") : "",
1068
+ // The one rule here that moves the page, and only while Select is
1069
+ // on: an emptied text's line of room, without which it cannot be
1070
+ // pointed at. See `emptyTextFields.ts` for why, and how narrowly.
1071
+ picking ? client.EMPTY_TEXT_RULES : "", highlighted ? highlightRule(highlighted, selectionColors.selection) : ""].filter(Boolean).join("\n")
764
1072
  }
765
1073
  });
766
1074
  }
@@ -857,28 +1165,118 @@ function isScrollable(el) {
857
1165
  };
858
1166
  return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
859
1167
  }
1168
+ var NO_PATHS = new Set();
1169
+
1170
+ /**
1171
+ * Start editing the first of `candidates` an element on the page shows and
1172
+ * nothing else: the picked element when it carries the candidate's path,
1173
+ * else the first element that does. `null` when none can be.
1174
+ *
1175
+ * What `editInline` does, and what a click does by itself when the Studio has
1176
+ * said ahead of it what the element's texts hold (`textFields`): one way to
1177
+ * start, whichever asked.
1178
+ */
1179
+ function startFirst(candidates, pick, options) {
1180
+ var reply = options.reply;
1181
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(candidates),
1182
+ _step;
1183
+ try {
1184
+ var _loop = function _loop() {
1185
+ var candidate = _step.value;
1186
+ var picked = pick !== null && pick.element.isConnected && pathOn(pick.element, candidate.path) !== null ? pick.element : null;
1187
+ var element = picked !== null && picked !== void 0 ? picked : findByPath(candidate.path);
1188
+ if (element === null) return 0; // continue
1189
+ var path = pathOn(element, candidate.path);
1190
+ if (path === null) return 0; // continue
1191
+ var editing = client.startInlineEditing(element, candidate, {
1192
+ // Where the click was, when it was on this element.
1193
+ at: picked !== null && pick !== null ? {
1194
+ x: pick.x,
1195
+ y: pick.y
1196
+ } : null,
1197
+ color: options.color,
1198
+ onChange: function onChange(value) {
1199
+ return reply({
1200
+ val: client.VAL_CANVAS_MESSAGE,
1201
+ type: "inlineEdit",
1202
+ path: path,
1203
+ value: value
1204
+ });
1205
+ },
1206
+ onEnd: function onEnd() {
1207
+ return reply({
1208
+ val: client.VAL_CANVAS_MESSAGE,
1209
+ type: "inlineEditEnded",
1210
+ path: path
1211
+ });
1212
+ },
1213
+ onSelection: function onSelection(selection, rect, caret) {
1214
+ return reply({
1215
+ val: client.VAL_CANVAS_MESSAGE,
1216
+ type: "inlineEditSelection",
1217
+ path: path,
1218
+ selection: selection,
1219
+ rect: rect,
1220
+ caret: caret
1221
+ });
1222
+ }
1223
+ });
1224
+ if (editing !== null) return {
1225
+ v: {
1226
+ editing: editing,
1227
+ path: path
1228
+ }
1229
+ };
1230
+ },
1231
+ _ret;
1232
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1233
+ _ret = _loop();
1234
+ if (_ret === 0) continue;
1235
+ if (_ret) return _ret.v;
1236
+ }
1237
+ } catch (err) {
1238
+ _iterator.e(err);
1239
+ } finally {
1240
+ _iterator.f();
1241
+ }
1242
+ return null;
1243
+ }
860
1244
  function findByPath(path) {
861
1245
  var elements = document.querySelectorAll("[data-val-path]");
862
1246
  for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
863
1247
  var el = _Array$from[_i];
864
- var attribute = el.getAttribute("data-val-path");
865
- if (!attribute) continue;
866
- // Compared as strings: the split returns branded `SourcePath`s and what
867
- // came back over `postMessage` is a plain string, which is the same value.
868
- if (core.Internal.splitJoinedSourcePaths(attribute).some(function (candidate) {
869
- return candidate === path;
870
- })) {
871
- return el;
872
- }
1248
+ if (pathOn(el, path) !== null) return el;
873
1249
  }
874
1250
  return null;
875
1251
  }
876
1252
 
1253
+ /**
1254
+ * `path` as `element` carries it, or null when it does not.
1255
+ *
1256
+ * Compared as strings: the split returns branded `SourcePath`s and what came
1257
+ * back over `postMessage` is a plain string, which is the same value. What is
1258
+ * returned is the element's own, so it is a `SourcePath` without anyone
1259
+ * having to say so.
1260
+ */
1261
+ function pathOn(element, path) {
1262
+ var _Internal$splitJoined;
1263
+ var attribute = element.getAttribute("data-val-path");
1264
+ if (!attribute) return null;
1265
+ return (_Internal$splitJoined = core.Internal.splitJoinedSourcePaths(attribute).find(function (candidate) {
1266
+ return candidate === path;
1267
+ })) !== null && _Internal$splitJoined !== void 0 ? _Internal$splitJoined : null;
1268
+ }
1269
+
877
1270
  /** What `screenshotPage` answers: the picture, or why it could not be taken. */
878
1271
  function screenshotReply(_x) {
879
1272
  return _screenshotReply.apply(this, arguments);
880
1273
  }
881
- /** What `readPage` answers: the page read, or why it could not be. */
1274
+ /**
1275
+ * The page's log (`pageLog.ts`). Started when the provider's module was
1276
+ * evaluated in the canvas, before hydration; started here, as late as the
1277
+ * bridge mounts, only if that did not happen -- a document that was not the
1278
+ * canvas when the provider loaded (see `isValCanvasFrame`).
1279
+ */
882
1280
  function _screenshotReply() {
883
1281
  _screenshotReply = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regenerator().m(function _callee2(message) {
884
1282
  var _t2, _t3, _t4, _t5;
@@ -920,17 +1318,49 @@ function _screenshotReply() {
920
1318
  }));
921
1319
  return _screenshotReply.apply(this, arguments);
922
1320
  }
1321
+ function pageLog() {
1322
+ return client.installPageLog(window);
1323
+ }
1324
+
1325
+ /** What `readPageLog` answers: the page's log, or why it could not be read. */
1326
+ function readPageLogReply(message) {
1327
+ try {
1328
+ return {
1329
+ val: client.VAL_CANVAS_MESSAGE,
1330
+ type: "pageLogRead",
1331
+ requestId: message.requestId,
1332
+ log: pageLog().read(objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, message.sinceNavigation !== undefined ? {
1333
+ sinceNavigation: message.sinceNavigation
1334
+ } : {}), message.levels !== undefined ? {
1335
+ levels: message.levels
1336
+ } : {}))
1337
+ };
1338
+ } catch (error) {
1339
+ return {
1340
+ val: client.VAL_CANVAS_MESSAGE,
1341
+ type: "pageLogRead",
1342
+ requestId: message.requestId,
1343
+ log: null,
1344
+ error: error instanceof Error ? error.message : String(error)
1345
+ };
1346
+ }
1347
+ }
1348
+
1349
+ /** What `readPage` answers: the page read, or why it could not be. */
923
1350
  function readPageReply(message) {
924
1351
  try {
925
1352
  return {
926
1353
  val: client.VAL_CANVAS_MESSAGE,
927
1354
  type: "pageRead",
928
1355
  requestId: message.requestId,
929
- snapshot: client.readPageSnapshot(document, objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, message.selector !== undefined ? {
1356
+ snapshot: objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, client.readPageSnapshot(document, objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, message.selector !== undefined ? {
930
1357
  selector: message.selector
931
1358
  } : {}), message.maxItems !== undefined ? {
932
1359
  maxItems: message.maxItems
933
- } : {}))
1360
+ } : {}))), {}, {
1361
+ // So the assistant notices the page threw without asking.
1362
+ log: pageLog().counts()
1363
+ })
934
1364
  };
935
1365
  } catch (error) {
936
1366
  return {
@@ -11,9 +11,9 @@ import { ValOverlayProvider } from './ValOverlayContext-51716662.esm.js';
11
11
  import { SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
12
12
  import { isDraft, windowCodeChangedReporter, createDraftStore, draftHolds, draftHoldsVersions, startRefreshLoop, dispatchCodeChanged, applyValEvent } from '@valbuild/react/internal';
13
13
  import { p as prefixStyles, u as useConfigStorageSave, f as floatDarkBg, d as floatLightBg, v as valPrefixedClass, c as cn } from './fallbackColors-0d915c59.esm.js';
14
- import { VAL_THEME_SESSION_STORAGE_KEY, isValCanvasFrame } from '@valbuild/shared/client';
14
+ import { VAL_THEME_SESSION_STORAGE_KEY, installPageLogInCanvasFrame, isValCanvasFrame } from '@valbuild/shared/client';
15
15
  import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-9209e9dd.esm.js';
16
- import { ValCanvasBridge } from './ValCanvasBridge-cf8d7967.esm.js';
16
+ import { ValCanvasBridge } from './ValCanvasBridge-719e6efe.esm.js';
17
17
  import { jsxs, jsx } from 'react/jsx-runtime';
18
18
  import './unsupportedIterableToArray-f57eb659.esm.js';
19
19
 
@@ -69,6 +69,19 @@ function hasValEnableCookie(cookieString) {
69
69
  return false;
70
70
  }
71
71
 
72
+ installPageLogInCanvasFrame(function () {
73
+ return hasValEnableCookie(document.cookie);
74
+ });
75
+
76
+ /**
77
+ * Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
78
+ */
79
+ /**
80
+ * How often `/draft/stat` is asked when nothing is in progress.
81
+ *
82
+ * Draft mode changes when someone toggles it, which the handshake below already
83
+ * covers — so this is only there to notice it being changed somewhere else.
84
+ */
72
85
  var DRAFT_IDLE_POLL_MS = 20000;
73
86
 
74
87
  /**
@@ -17,7 +17,7 @@ var internal = require('@valbuild/react/internal');
17
17
  var fallbackColors = require('./fallbackColors-38f01ad2.cjs.dev.js');
18
18
  var client = require('@valbuild/shared/client');
19
19
  var createForOfIteratorHelper = require('./createForOfIteratorHelper-9c6aa3c7.cjs.dev.js');
20
- var ValCanvasBridge = require('./ValCanvasBridge-fc46ab88.cjs.dev.js');
20
+ var ValCanvasBridge = require('./ValCanvasBridge-9b2df334.cjs.dev.js');
21
21
  var jsxRuntime = require('react/jsx-runtime');
22
22
  require('./unsupportedIterableToArray-20a9209f.cjs.dev.js');
23
23
 
@@ -96,6 +96,19 @@ function hasValEnableCookie(cookieString) {
96
96
  return false;
97
97
  }
98
98
 
99
+ client.installPageLogInCanvasFrame(function () {
100
+ return hasValEnableCookie(document.cookie);
101
+ });
102
+
103
+ /**
104
+ * Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
105
+ */
106
+ /**
107
+ * How often `/draft/stat` is asked when nothing is in progress.
108
+ *
109
+ * Draft mode changes when someone toggles it, which the handshake below already
110
+ * covers — so this is only there to notice it being changed somewhere else.
111
+ */
99
112
  var DRAFT_IDLE_POLL_MS = 20000;
100
113
 
101
114
  /**