@valbuild/next 0.153.6 → 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # @valbuild/next
2
2
 
3
+ ## 0.154.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1060](https://github.com/valbuild/val/pull/1060) [`c71a92c`](https://github.com/valbuild/val/commit/c71a92ccc40eed16c9b2669d6b26efee51240eea) Thanks [@freekh](https://github.com/freekh)! - The assistant can now use the page in the preview, not only read it. A new `interact_page` tool opens a path on the site, clicks an element, types into a field, presses a key (Enter, Escape, Tab, the arrows), or shows the page at phone, tablet or desktop width — and answers with the page as it is afterwards: it waits for the page to settle (no changes and no requests in flight for a moment, at most 15 seconds), then gives the page's outline, whether the address or title changed, and what the page logged as going wrong since. When the page is still busy after that, the answer says so instead of describing it as finished. The assistant is told to use it to check its own changes: after a quick preview or a build, open the route, try what changed, and read the log.
8
+
9
+ The preview is the real site, talking to its real backend. What is enforced:
10
+
11
+ - **Every click, and every Enter or Space, asks you first.** A card in the chat — written by the Studio, not the assistant — names the element as the page shows it (its label, what it is, the page it is on, and whether Enter would submit its form), and nothing reaches the page until you allow it. Allow does exactly that, once, on that element; if the element changed in the meantime, you are asked again.
12
+ - **While the assistant types, presses other keys, or waits for a page it opened or resized to settle,** requests the page makes with any method but `GET`, `HEAD` and `OPTIONS` are held until the page settles, and a card shows each one — its method, its address and an excerpt of what it sends. Allow sends exactly those, as they were; Don't allow, or stopping the answer, drops them and the page sees them fail.
13
+ - **Sends of data to another site** (`POST`, `PUT`, `PATCH`, `DELETE`, forms, beacons) are refused, and so are links and forms that go to another site or open a new window. It never types into a password field.
14
+ - After a web search in the same answer, the assistant asks before it uses the preview at all.
15
+
16
+ What is **not** covered:
17
+
18
+ - requests a page sends while it loads, after `open` or after any navigation, and requests sent later on their own (an autosave after a delay);
19
+ - requests made through a `fetch` or `XMLHttpRequest` the page's code captured before the action (some libraries do this), and XHRs opened before it;
20
+ - `GET`, `HEAD` and `OPTIONS` requests — a `GET` to another site can still carry data in its address — and image or script loads;
21
+ - WebSockets, workers and embedded frames;
22
+ - script navigations and redirects, which can still leave the site; and plain links, which can have side effects of their own, such as a logout or unsubscribe link.
23
+
24
+ The ask-first rule is `interact_page`'s, not the whole session's: `quick_preview` runs code the assistant wrote in the preview, and what that code does is not asked about.
25
+
26
+ Reading pages needs no permission. Width changes use the preview's own device switch, so you see the same width the assistant does.
27
+
28
+ Update `@valbuild/next` or `@valbuild/tanstack` together with the Studio to get `interact_page`; with an older one, the tool says at once which package to update.
29
+
30
+ - [#1053](https://github.com/valbuild/val/pull/1053) [`af4f6fc`](https://github.com/valbuild/val/commit/af4f6fc2b2f344ca474fc80664365a6fac4325b1) Thanks [@freekh](https://github.com/freekh)! - **Select & edit.** Text can now be edited where it is, in the Studio's preview, instead of in the column beside it. Select has a menu beside it with two modes:
31
+
32
+ - **Select** opens the field you click in the column, as before. It is the mode Select starts in.
33
+ - **Select & edit** puts the caret in the text you click, on the page. The mode you used last is remembered per browser.
34
+
35
+ In Select & edit:
36
+
37
+ - **Strings** — a headline, a label, a link's words. Enter ends the edit (in a `.multiline()` string it is a new line), Esc ends it too.
38
+ - **Richtext** rendered with `ValRichText` — type and delete anywhere, Enter splits a paragraph, heading or list item, Backspace and Delete join them. Formatting controls float beside the text: bold, italic, strikethrough, links, headings and lists, whichever the field's schema allows. They are the same controls the field has in the column, and pressed with only a caret they apply to what you type next. Undo and redo (Ctrl/Cmd+Z, Ctrl/Cmd+Shift+Z, Ctrl+Y) go back over typing, Enter, Backspace and the controls alike.
39
+
40
+ The caret goes in as you click, so you can start typing straight away. A text you have emptied stays on the page as a line you can click while Select is on, in either mode, so you can pick it or type in it again; with Select off the page is laid out as before.
41
+
42
+ While you type, the "On this page" column scrolls to the same field and shows it selected, with what you type appearing in it. A validation error for the field shows by the text on the page as well as in the column, and goes when you fix it. Zooming the preview, fitting it or changing its width does not end the edit: the caret stays in the text and you can keep typing. Reloading the page, changing its address or leaving the preview ends the edit, and what you typed is saved.
43
+
44
+ Everything else still opens in the column when clicked: a field that is not a text (an image, a number, a date), a text the page shows as part of something larger (inside a sentence, in an `alt` or `href`), a richtext rendered with a `transform` that changes its structure, and a `readonly` field. Images cannot be added to a richtext from the page yet.
45
+
46
+ Update `@valbuild/next` or `@valbuild/tanstack` together with the Studio to use it. A site on an older version is unaffected: in either mode, every click opens the field in the column.
47
+
48
+ - Updated dependencies [[`d2956df`](https://github.com/valbuild/val/commit/d2956df9d82f7cba1cd26a754ccbd0fa10a5d641), [`c71a92c`](https://github.com/valbuild/val/commit/c71a92ccc40eed16c9b2669d6b26efee51240eea), [`9ee9bdf`](https://github.com/valbuild/val/commit/9ee9bdf8f1feb57b2ab2f70c82a8c839256f8687), [`af4f6fc`](https://github.com/valbuild/val/commit/af4f6fc2b2f344ca474fc80664365a6fac4325b1), [`70bd897`](https://github.com/valbuild/val/commit/70bd89741d23f89407ddab56de2a70ad62e79fee), [`0b1cbe6`](https://github.com/valbuild/val/commit/0b1cbe6858094b21fa15a8fa9b88d5f4304d68e1), [`d85f2d7`](https://github.com/valbuild/val/commit/d85f2d75c3dd2732ad1fb9f0c6c0023f4f5de834), [`7f49d72`](https://github.com/valbuild/val/commit/7f49d72b5d2a447025cfec474ff1d85b21e4333e)]:
49
+ - @valbuild/ui@0.154.0
50
+ - @valbuild/shared@0.154.0
51
+ - @valbuild/server@0.154.0
52
+ - @valbuild/react@0.154.0
53
+ - @valbuild/language-server@0.154.0
54
+ - @valbuild/mcp@0.154.0
55
+
3
56
  ## 0.153.6
4
57
 
5
58
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./ValCanvasBridge-063ad333.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./ValCanvasBridge-063ad333.cjs.dev.js");
7
+ }
@@ -3,6 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
+ var createForOfIteratorHelper = require('./createForOfIteratorHelper-8459fbc7.cjs.prod.js');
6
7
  var asyncToGenerator = require('./asyncToGenerator-8e5c36c8.cjs.prod.js');
7
8
  var unsupportedIterableToArray = require('./unsupportedIterableToArray-1aadf9fb.cjs.prod.js');
8
9
  var objectSpread2 = require('./objectSpread2-469273e9.cjs.prod.js');
@@ -10,7 +11,7 @@ var slicedToArray = require('./slicedToArray-0fc63719.cjs.prod.js');
10
11
  var React = require('react');
11
12
  var core = require('@valbuild/core');
12
13
  var client = require('@valbuild/shared/client');
13
- var version = require('./version-6df1633a.cjs.prod.js');
14
+ var version = require('./version-4d44d9cd.cjs.prod.js');
14
15
  var jsxRuntime = require('react/jsx-runtime');
15
16
 
16
17
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
@@ -47,6 +48,13 @@ var DEFAULT_SELECTION = {
47
48
  */
48
49
  var RESCAN_INTERVAL_MS = 5000;
49
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
+
50
58
  /**
51
59
  * The page's half of the canvas protocol.
52
60
  *
@@ -111,6 +119,50 @@ function ValCanvasBridge(_ref) {
111
119
  return (_stopRestoring$curren = stopRestoring.current) === null || _stopRestoring$curren === void 0 ? void 0 : _stopRestoring$curren.call(stopRestoring);
112
120
  };
113
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;
114
166
  var post = React__default["default"].useCallback(function (message) {
115
167
  // `*` as the target origin: the studio and the page share an origin today,
116
168
  // but the frame does not know the parent's origin for certain and naming
@@ -132,6 +184,10 @@ function ValCanvasBridge(_ref) {
132
184
 
133
185
  /** Every element Val tagged, with where it is on the page. */
134
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);
135
191
  var elements = [];
136
192
  var scrollX = window.scrollX;
137
193
  var scrollY = window.scrollY;
@@ -222,6 +278,7 @@ function ValCanvasBridge(_ref) {
222
278
  // What this bridge answers, so the Studio never waits on a request
223
279
  // it would not: see `capabilities` in the protocol.
224
280
  capabilities: _toConsumableArray(client.BRIDGE_CAPABILITIES),
281
+ document: DOCUMENT_ID,
225
282
  bridge: {
226
283
  "package": "@valbuild/next",
227
284
  version: version.VERSION
@@ -339,6 +396,22 @@ function ValCanvasBridge(_ref) {
339
396
  setPicking(message.picking);
340
397
  return;
341
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
+ }
342
415
  if (message.type === "pickElements") {
343
416
  var _message$color;
344
417
  setElementPicking({
@@ -381,15 +454,50 @@ function ValCanvasBridge(_ref) {
381
454
  window.parent.postMessage(readPageLogReply(message), _asker);
382
455
  return;
383
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
+ }
384
492
  if (message.type === "screenshotPage") {
385
493
  // The assistant's `screenshot_page`: a picture of the page, drawn
386
494
  // here. As `readPage`: only for the frame's parent, when that is the
387
495
  // Studio here, and answered to it alone.
388
496
  if (event.source !== window.parent) return;
389
- var _asker2 = event.origin;
390
- if (_asker2 !== window.location.origin) return;
497
+ var _asker3 = event.origin;
498
+ if (_asker3 !== window.location.origin) return;
391
499
  void screenshotReply(message).then(function (reply) {
392
- return window.parent.postMessage(reply, _asker2);
500
+ return window.parent.postMessage(reply, _asker3);
393
501
  });
394
502
  return;
395
503
  }
@@ -440,6 +548,98 @@ function ValCanvasBridge(_ref) {
440
548
  }))();
441
549
  return;
442
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
+ }
443
643
  if (message.type === "theme") {
444
644
  setSelectionColors({
445
645
  selection: message.selection,
@@ -555,18 +755,85 @@ function ValCanvasBridge(_ref) {
555
755
  */
556
756
  React__default["default"].useEffect(function () {
557
757
  var onClick = function onClick(event) {
558
- if (!pickingRef.current) return;
758
+ var _heldKeys$current2;
559
759
  var target = event.target;
560
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;
561
772
  var tagged = target.closest("[data-val-path]");
562
773
  var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
563
- if (!attribute) return;
774
+ if (!tagged || !attribute) return;
564
775
  event.preventDefault();
565
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;
566
833
  post({
567
834
  val: client.VAL_CANVAS_MESSAGE,
568
835
  type: "clicked",
569
- paths: core.Internal.splitJoinedSourcePaths(attribute)
836
+ paths: paths
570
837
  });
571
838
  };
572
839
  document.addEventListener("click", onClick, {
@@ -579,6 +846,17 @@ function ValCanvasBridge(_ref) {
579
846
  };
580
847
  }, [post]);
581
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
+
582
860
  // Esc while picking fields: the key goes to the page, which has the focus
583
861
  // once it has been clicked, so the studio hears of it only from here.
584
862
  React__default["default"].useEffect(function () {
@@ -786,7 +1064,11 @@ function ValCanvasBridge(_ref) {
786
1064
  // CSS string. A path contains quotes (`?p="/"`) and would otherwise
787
1065
  // close the selector early.
788
1066
  dangerouslySetInnerHTML: {
789
- __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")
790
1072
  }
791
1073
  });
792
1074
  }
@@ -883,23 +1165,108 @@ function isScrollable(el) {
883
1165
  };
884
1166
  return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
885
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
+ }
886
1244
  function findByPath(path) {
887
1245
  var elements = document.querySelectorAll("[data-val-path]");
888
1246
  for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
889
1247
  var el = _Array$from[_i];
890
- var attribute = el.getAttribute("data-val-path");
891
- if (!attribute) continue;
892
- // Compared as strings: the split returns branded `SourcePath`s and what
893
- // came back over `postMessage` is a plain string, which is the same value.
894
- if (core.Internal.splitJoinedSourcePaths(attribute).some(function (candidate) {
895
- return candidate === path;
896
- })) {
897
- return el;
898
- }
1248
+ if (pathOn(el, path) !== null) return el;
899
1249
  }
900
1250
  return null;
901
1251
  }
902
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
+
903
1270
  /** What `screenshotPage` answers: the picture, or why it could not be taken. */
904
1271
  function screenshotReply(_x) {
905
1272
  return _screenshotReply.apply(this, arguments);