@valbuild/tanstack 0.153.6 → 0.154.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/dist/valbuild-tanstack.cjs.dev.js +383 -17
- package/dist/valbuild-tanstack.cjs.prod.js +383 -17
- package/dist/valbuild-tanstack.esm.js +384 -18
- package/dist/{version-c72b9e12.cjs.prod.js → version-04b9b5af.cjs.prod.js} +1 -1
- package/dist/{version-bee0c459.cjs.dev.js → version-43593a0a.cjs.dev.js} +1 -1
- package/dist/{version-83ae9dc3.esm.js → version-b7539dd8.esm.js} +1 -1
- package/package.json +7 -7
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +1 -1
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +1 -1
- package/server/dist/valbuild-tanstack-server.esm.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# @valbuild/tanstack
|
|
2
2
|
|
|
3
|
+
## 0.154.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`37e4f39`](https://github.com/valbuild/val/commit/37e4f390d1fd6a930488c9487de43f8c1a390122), [`245843e`](https://github.com/valbuild/val/commit/245843ec527212dc31c6e1da1f0bd5f9d99cf8d3), [`d4e514f`](https://github.com/valbuild/val/commit/d4e514f9eac2f014fc07aa768787d637898dc744), [`def1434`](https://github.com/valbuild/val/commit/def1434324a0b3e26202148cb11726e02bd5bffe), [`82c641c`](https://github.com/valbuild/val/commit/82c641ca00ddfe1ed5b07b9ccb5ee39b0c6f102e)]:
|
|
8
|
+
- @valbuild/ui@0.154.1
|
|
9
|
+
- @valbuild/server@0.154.1
|
|
10
|
+
- @valbuild/shared@0.154.1
|
|
11
|
+
- @valbuild/react@0.154.1
|
|
12
|
+
- @valbuild/language-server@0.154.1
|
|
13
|
+
- @valbuild/mcp@0.154.1
|
|
14
|
+
|
|
15
|
+
## 0.154.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#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.
|
|
20
|
+
|
|
21
|
+
The preview is the real site, talking to its real backend. What is enforced:
|
|
22
|
+
|
|
23
|
+
- **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.
|
|
24
|
+
- **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.
|
|
25
|
+
- **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.
|
|
26
|
+
- After a web search in the same answer, the assistant asks before it uses the preview at all.
|
|
27
|
+
|
|
28
|
+
What is **not** covered:
|
|
29
|
+
|
|
30
|
+
- 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);
|
|
31
|
+
- requests made through a `fetch` or `XMLHttpRequest` the page's code captured before the action (some libraries do this), and XHRs opened before it;
|
|
32
|
+
- `GET`, `HEAD` and `OPTIONS` requests — a `GET` to another site can still carry data in its address — and image or script loads;
|
|
33
|
+
- WebSockets, workers and embedded frames;
|
|
34
|
+
- 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.
|
|
35
|
+
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
Reading pages needs no permission. Width changes use the preview's own device switch, so you see the same width the assistant does.
|
|
39
|
+
|
|
40
|
+
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.
|
|
41
|
+
|
|
42
|
+
- [#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:
|
|
43
|
+
|
|
44
|
+
- **Select** opens the field you click in the column, as before. It is the mode Select starts in.
|
|
45
|
+
- **Select & edit** puts the caret in the text you click, on the page. The mode you used last is remembered per browser.
|
|
46
|
+
|
|
47
|
+
In Select & edit:
|
|
48
|
+
|
|
49
|
+
- **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.
|
|
50
|
+
- **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.
|
|
51
|
+
|
|
52
|
+
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.
|
|
53
|
+
|
|
54
|
+
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.
|
|
55
|
+
|
|
56
|
+
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.
|
|
57
|
+
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
- 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)]:
|
|
61
|
+
- @valbuild/ui@0.154.0
|
|
62
|
+
- @valbuild/shared@0.154.0
|
|
63
|
+
- @valbuild/server@0.154.0
|
|
64
|
+
- @valbuild/react@0.154.0
|
|
65
|
+
- @valbuild/language-server@0.154.0
|
|
66
|
+
- @valbuild/mcp@0.154.0
|
|
67
|
+
|
|
3
68
|
## 0.153.6
|
|
4
69
|
|
|
5
70
|
### Patch Changes
|
|
@@ -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-
|
|
9
|
+
var version = require('./version-43593a0a.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;
|
|
@@ -438,6 +493,7 @@ function ValCanvasBridge(_ref) {
|
|
|
438
493
|
// What this bridge answers, so the Studio never waits on a request
|
|
439
494
|
// it would not: see `capabilities` in the protocol.
|
|
440
495
|
capabilities: _toConsumableArray(client.BRIDGE_CAPABILITIES),
|
|
496
|
+
document: DOCUMENT_ID,
|
|
441
497
|
bridge: {
|
|
442
498
|
"package": "@valbuild/tanstack",
|
|
443
499
|
version: version.VERSION
|
|
@@ -555,6 +611,22 @@ function ValCanvasBridge(_ref) {
|
|
|
555
611
|
setPicking(message.picking);
|
|
556
612
|
return;
|
|
557
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
|
+
}
|
|
558
630
|
if (message.type === "pickElements") {
|
|
559
631
|
var _message$color;
|
|
560
632
|
setElementPicking({
|
|
@@ -597,15 +669,50 @@ function ValCanvasBridge(_ref) {
|
|
|
597
669
|
window.parent.postMessage(readPageLogReply(message), _asker);
|
|
598
670
|
return;
|
|
599
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
|
+
}
|
|
600
707
|
if (message.type === "screenshotPage") {
|
|
601
708
|
// The assistant's `screenshot_page`: a picture of the page, drawn
|
|
602
709
|
// here. As `readPage`: only for the frame's parent, when that is the
|
|
603
710
|
// Studio here, and answered to it alone.
|
|
604
711
|
if (event.source !== window.parent) return;
|
|
605
|
-
var
|
|
606
|
-
if (
|
|
712
|
+
var _asker3 = event.origin;
|
|
713
|
+
if (_asker3 !== window.location.origin) return;
|
|
607
714
|
void screenshotReply(message).then(function (reply) {
|
|
608
|
-
return window.parent.postMessage(reply,
|
|
715
|
+
return window.parent.postMessage(reply, _asker3);
|
|
609
716
|
});
|
|
610
717
|
return;
|
|
611
718
|
}
|
|
@@ -656,6 +763,98 @@ function ValCanvasBridge(_ref) {
|
|
|
656
763
|
}))();
|
|
657
764
|
return;
|
|
658
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
|
+
}
|
|
659
858
|
if (message.type === "theme") {
|
|
660
859
|
setSelectionColors({
|
|
661
860
|
selection: message.selection,
|
|
@@ -771,18 +970,85 @@ function ValCanvasBridge(_ref) {
|
|
|
771
970
|
*/
|
|
772
971
|
React__default["default"].useEffect(function () {
|
|
773
972
|
var onClick = function onClick(event) {
|
|
774
|
-
|
|
973
|
+
var _heldKeys$current2;
|
|
775
974
|
var target = event.target;
|
|
776
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;
|
|
777
987
|
var tagged = target.closest("[data-val-path]");
|
|
778
988
|
var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
|
|
779
|
-
if (!attribute) return;
|
|
989
|
+
if (!tagged || !attribute) return;
|
|
780
990
|
event.preventDefault();
|
|
781
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;
|
|
782
1048
|
post({
|
|
783
1049
|
val: client.VAL_CANVAS_MESSAGE,
|
|
784
1050
|
type: "clicked",
|
|
785
|
-
paths:
|
|
1051
|
+
paths: paths
|
|
786
1052
|
});
|
|
787
1053
|
};
|
|
788
1054
|
document.addEventListener("click", onClick, {
|
|
@@ -795,6 +1061,17 @@ function ValCanvasBridge(_ref) {
|
|
|
795
1061
|
};
|
|
796
1062
|
}, [post]);
|
|
797
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
|
+
|
|
798
1075
|
// Esc while picking fields: the key goes to the page, which has the focus
|
|
799
1076
|
// once it has been clicked, so the studio hears of it only from here.
|
|
800
1077
|
React__default["default"].useEffect(function () {
|
|
@@ -1002,7 +1279,11 @@ function ValCanvasBridge(_ref) {
|
|
|
1002
1279
|
// CSS string. A path contains quotes (`?p="/"`) and would otherwise
|
|
1003
1280
|
// close the selector early.
|
|
1004
1281
|
dangerouslySetInnerHTML: {
|
|
1005
|
-
__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, "; }") : "",
|
|
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")
|
|
1006
1287
|
}
|
|
1007
1288
|
});
|
|
1008
1289
|
}
|
|
@@ -1099,23 +1380,108 @@ function isScrollable(el) {
|
|
|
1099
1380
|
};
|
|
1100
1381
|
return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
|
|
1101
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
|
+
}
|
|
1102
1459
|
function findByPath(path) {
|
|
1103
1460
|
var elements = document.querySelectorAll("[data-val-path]");
|
|
1104
1461
|
for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
|
|
1105
1462
|
var el = _Array$from[_i];
|
|
1106
|
-
|
|
1107
|
-
if (!attribute) continue;
|
|
1108
|
-
// Compared as strings: the split returns branded `SourcePath`s and what
|
|
1109
|
-
// came back over `postMessage` is a plain string, which is the same value.
|
|
1110
|
-
if (core.Internal.splitJoinedSourcePaths(attribute).some(function (candidate) {
|
|
1111
|
-
return candidate === path;
|
|
1112
|
-
})) {
|
|
1113
|
-
return el;
|
|
1114
|
-
}
|
|
1463
|
+
if (pathOn(el, path) !== null) return el;
|
|
1115
1464
|
}
|
|
1116
1465
|
return null;
|
|
1117
1466
|
}
|
|
1118
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
|
+
|
|
1119
1485
|
/** What `screenshotPage` answers: the picture, or why it could not be taken. */
|
|
1120
1486
|
function screenshotReply(_x) {
|
|
1121
1487
|
return _screenshotReply.apply(this, arguments);
|