@valbuild/next 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/{ValCanvasBridge-1f98937c.cjs.dev.js → ValCanvasBridge-85e75bdb.cjs.dev.js} +384 -17
- package/dist/{ValCanvasBridge-4f025b11.esm.js → ValCanvasBridge-d18c2be6.esm.js} +385 -18
- package/dist/ValCanvasBridge-fc476670.cjs.js +7 -0
- package/dist/{ValCanvasBridge-d0230cd2.cjs.prod.js → ValCanvasBridge-fc476670.cjs.prod.js} +384 -17
- package/dist/ValNextProvider-27242758.esm.js +1 -1
- package/dist/ValNextProvider-4838fed0.cjs.dev.js +1 -1
- package/dist/ValNextProvider-9343dc1e.cjs.prod.js +1 -1
- package/dist/valbuild-next.cjs.dev.js +1 -1
- package/dist/valbuild-next.cjs.prod.js +1 -1
- package/dist/valbuild-next.esm.js +1 -1
- package/dist/{version-6bcddc39.cjs.dev.js → version-2a0df4d8.cjs.dev.js} +1 -1
- package/dist/{version-6df1633a.cjs.prod.js → version-48aba9c6.cjs.prod.js} +1 -1
- package/dist/{version-73b4e0ba.esm.js → version-d945c1eb.esm.js} +1 -1
- package/package.json +7 -7
- package/rsc/dist/valbuild-next-rsc.cjs.dev.js +1 -1
- package/rsc/dist/valbuild-next-rsc.cjs.prod.js +1 -1
- package/rsc/dist/valbuild-next-rsc.esm.js +1 -1
- package/server/dist/valbuild-next-server.cjs.dev.js +1 -1
- package/server/dist/valbuild-next-server.cjs.prod.js +1 -1
- package/server/dist/valbuild-next-server.esm.js +1 -1
- package/dist/ValCanvasBridge-d0230cd2.cjs.js +0 -7
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
+
import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-9209e9dd.esm.js';
|
|
2
3
|
import { _ as _asyncToGenerator, a as _regenerator } from './asyncToGenerator-500f022f.esm.js';
|
|
3
4
|
import { a as _arrayLikeToArray, _ as _unsupportedIterableToArray } from './unsupportedIterableToArray-f57eb659.esm.js';
|
|
4
5
|
import { _ as _objectSpread2 } from './objectSpread2-f1f0d77a.esm.js';
|
|
5
6
|
import { _ as _slicedToArray } from './slicedToArray-5ff32315.esm.js';
|
|
6
7
|
import React from 'react';
|
|
7
8
|
import { Internal } from '@valbuild/core';
|
|
8
|
-
import { VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, installPageLog, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, isValCanvasStudioMessage, restoreScroll, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, isCodeChangedDetail, screenshotPage, readPageSnapshot, BRIDGE_CAPABILITIES } from '@valbuild/shared/client';
|
|
9
|
-
import { V as VERSION } from './version-
|
|
9
|
+
import { markEmptyTextFields, VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, EMPTY_TEXT_RULES, installPageLog, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, isValCanvasStudioMessage, restoreScroll, interactWithPage, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, replayKeys, isCodeChangedDetail, holdKeys, startInlineEditing, screenshotPage, readPageSnapshot, BRIDGE_CAPABILITIES } from '@valbuild/shared/client';
|
|
10
|
+
import { V as VERSION } from './version-d945c1eb.esm.js';
|
|
10
11
|
import { jsx } from 'react/jsx-runtime';
|
|
11
12
|
|
|
12
13
|
function _arrayWithoutHoles(r) {
|
|
@@ -39,6 +40,13 @@ var DEFAULT_SELECTION = {
|
|
|
39
40
|
*/
|
|
40
41
|
var RESCAN_INTERVAL_MS = 5000;
|
|
41
42
|
|
|
43
|
+
/**
|
|
44
|
+
* This document, among the ones the frame loads: sent with every `ready`
|
|
45
|
+
* (see `document` there). Made when the module is evaluated, which is once
|
|
46
|
+
* per document. Not `crypto.randomUUID`, which an insecure context lacks.
|
|
47
|
+
*/
|
|
48
|
+
var DOCUMENT_ID = "".concat(Date.now().toString(36), "-").concat(Math.random().toString(36).slice(2));
|
|
49
|
+
|
|
42
50
|
/**
|
|
43
51
|
* The page's half of the canvas protocol.
|
|
44
52
|
*
|
|
@@ -103,6 +111,50 @@ function ValCanvasBridge(_ref) {
|
|
|
103
111
|
return (_stopRestoring$curren = stopRestoring.current) === null || _stopRestoring$curren === void 0 ? void 0 : _stopRestoring$curren.call(stopRestoring);
|
|
104
112
|
};
|
|
105
113
|
}, []);
|
|
114
|
+
/**
|
|
115
|
+
* The field being edited on the page itself (`editInline`), or the last
|
|
116
|
+
* one that was, while its copy waits for the page to catch up. See
|
|
117
|
+
* `inlineEditing.ts` in `@valbuild/shared`, which both bindings run.
|
|
118
|
+
*/
|
|
119
|
+
var inlineEditing = React.useRef(null);
|
|
120
|
+
React.useEffect(function () {
|
|
121
|
+
return function () {
|
|
122
|
+
var _inlineEditing$curren;
|
|
123
|
+
return (_inlineEditing$curren = inlineEditing.current) === null || _inlineEditing$curren === void 0 ? void 0 : _inlineEditing$curren.release();
|
|
124
|
+
};
|
|
125
|
+
}, []);
|
|
126
|
+
/**
|
|
127
|
+
* The last pick: the element and where on it. `editInline` is the Studio's
|
|
128
|
+
* answer to a `clicked`, and the caret belongs where that click was.
|
|
129
|
+
*/
|
|
130
|
+
var lastPick = React.useRef(null);
|
|
131
|
+
/**
|
|
132
|
+
* The page's texts as the Studio last said (`textFields`), and the origin
|
|
133
|
+
* that said it, which is the only one an edit started from them answers.
|
|
134
|
+
* `null` until it says: a Studio that predates it never does, and every
|
|
135
|
+
* click then asks, as before.
|
|
136
|
+
*/
|
|
137
|
+
var textFields = React.useRef(null);
|
|
138
|
+
/**
|
|
139
|
+
* Whether the edit in progress was started here, in a click, rather than
|
|
140
|
+
* by `editInline`: an `editInline` that arrives after it answers a click
|
|
141
|
+
* from before it, and must not take the caret away.
|
|
142
|
+
*/
|
|
143
|
+
var startedOnClick = React.useRef(false);
|
|
144
|
+
/**
|
|
145
|
+
* The keys pressed since a click the Studio was asked about, until it
|
|
146
|
+
* answers: see `inlineEditKeys.ts`.
|
|
147
|
+
*/
|
|
148
|
+
var heldKeys = React.useRef(null);
|
|
149
|
+
React.useEffect(function () {
|
|
150
|
+
return function () {
|
|
151
|
+
var _heldKeys$current;
|
|
152
|
+
(_heldKeys$current = heldKeys.current) === null || _heldKeys$current === void 0 || _heldKeys$current.release();
|
|
153
|
+
};
|
|
154
|
+
}, []);
|
|
155
|
+
// Read when an edit starts, long after the render that set it.
|
|
156
|
+
var selectionColor = React.useRef(selectionColors.selection);
|
|
157
|
+
selectionColor.current = selectionColors.selection;
|
|
106
158
|
var post = React.useCallback(function (message) {
|
|
107
159
|
// `*` as the target origin: the studio and the page share an origin today,
|
|
108
160
|
// but the frame does not know the parent's origin for certain and naming
|
|
@@ -124,6 +176,10 @@ function ValCanvasBridge(_ref) {
|
|
|
124
176
|
|
|
125
177
|
/** Every element Val tagged, with where it is on the page. */
|
|
126
178
|
var scan = React.useCallback(function () {
|
|
179
|
+
var _textFields$current$e, _textFields$current;
|
|
180
|
+
// Before measuring: an emptied text measures with the room it is given
|
|
181
|
+
// while Select is on, so the Studio's outline of it has a size too.
|
|
182
|
+
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, Internal.splitJoinedSourcePaths);
|
|
127
183
|
var elements = [];
|
|
128
184
|
var scrollX = window.scrollX;
|
|
129
185
|
var scrollY = window.scrollY;
|
|
@@ -214,6 +270,7 @@ function ValCanvasBridge(_ref) {
|
|
|
214
270
|
// What this bridge answers, so the Studio never waits on a request
|
|
215
271
|
// it would not: see `capabilities` in the protocol.
|
|
216
272
|
capabilities: _toConsumableArray(BRIDGE_CAPABILITIES),
|
|
273
|
+
document: DOCUMENT_ID,
|
|
217
274
|
bridge: {
|
|
218
275
|
"package": "@valbuild/next",
|
|
219
276
|
version: VERSION
|
|
@@ -331,6 +388,22 @@ function ValCanvasBridge(_ref) {
|
|
|
331
388
|
setPicking(message.picking);
|
|
332
389
|
return;
|
|
333
390
|
}
|
|
391
|
+
if (message.type === "textFields") {
|
|
392
|
+
// What starts an edit on a click, so as `editInline`: only from the
|
|
393
|
+
// frame's parent, when that is the Studio here.
|
|
394
|
+
if (event.source !== window.parent) return;
|
|
395
|
+
if (event.origin !== window.location.origin) return;
|
|
396
|
+
textFields.current = {
|
|
397
|
+
editing: message.editing,
|
|
398
|
+
editable: new Map(message.editable.map(function (candidate) {
|
|
399
|
+
return [candidate.path, candidate];
|
|
400
|
+
})),
|
|
401
|
+
empty: new Set(message.empty),
|
|
402
|
+
origin: event.origin
|
|
403
|
+
};
|
|
404
|
+
scan();
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
334
407
|
if (message.type === "pickElements") {
|
|
335
408
|
var _message$color;
|
|
336
409
|
setElementPicking({
|
|
@@ -373,15 +446,50 @@ function ValCanvasBridge(_ref) {
|
|
|
373
446
|
window.parent.postMessage(readPageLogReply(message), _asker);
|
|
374
447
|
return;
|
|
375
448
|
}
|
|
449
|
+
if (message.type === "interact") {
|
|
450
|
+
// The assistant's `interact_page`: do something on the page and
|
|
451
|
+
// read it once it settled (`pageInteraction.ts`) -- a click or
|
|
452
|
+
// Enter/Space only once the person allowed it. As
|
|
453
|
+
// `readPage`: only for the frame's parent, when that is the Studio
|
|
454
|
+
// here, and answered to it alone.
|
|
455
|
+
if (event.source !== window.parent) return;
|
|
456
|
+
var _asker2 = event.origin;
|
|
457
|
+
if (_asker2 !== window.location.origin) return;
|
|
458
|
+
var requestId = message.requestId;
|
|
459
|
+
void interactWithPage(window, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
460
|
+
action: message.action
|
|
461
|
+
}, message.maxItems !== undefined ? {
|
|
462
|
+
maxItems: message.maxItems
|
|
463
|
+
} : {}), message.timeoutMs !== undefined ? {
|
|
464
|
+
timeoutMs: message.timeoutMs
|
|
465
|
+
} : {}), message.logFrom !== undefined ? {
|
|
466
|
+
logFrom: message.logFrom
|
|
467
|
+
} : {}), message.approved !== undefined ? {
|
|
468
|
+
approved: message.approved
|
|
469
|
+
} : {}), {}, {
|
|
470
|
+
document: DOCUMENT_ID
|
|
471
|
+
}), pageLog()).then(function (outcome) {
|
|
472
|
+
var answer = {
|
|
473
|
+
val: VAL_CANVAS_MESSAGE,
|
|
474
|
+
type: "interacted",
|
|
475
|
+
requestId: requestId,
|
|
476
|
+
outcome: outcome,
|
|
477
|
+
// Which document answered: see `interacted` in the protocol.
|
|
478
|
+
document: DOCUMENT_ID
|
|
479
|
+
};
|
|
480
|
+
window.parent.postMessage(answer, _asker2);
|
|
481
|
+
});
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
376
484
|
if (message.type === "screenshotPage") {
|
|
377
485
|
// The assistant's `screenshot_page`: a picture of the page, drawn
|
|
378
486
|
// here. As `readPage`: only for the frame's parent, when that is the
|
|
379
487
|
// Studio here, and answered to it alone.
|
|
380
488
|
if (event.source !== window.parent) return;
|
|
381
|
-
var
|
|
382
|
-
if (
|
|
489
|
+
var _asker3 = event.origin;
|
|
490
|
+
if (_asker3 !== window.location.origin) return;
|
|
383
491
|
void screenshotReply(message).then(function (reply) {
|
|
384
|
-
return window.parent.postMessage(reply,
|
|
492
|
+
return window.parent.postMessage(reply, _asker3);
|
|
385
493
|
});
|
|
386
494
|
return;
|
|
387
495
|
}
|
|
@@ -432,6 +540,98 @@ function ValCanvasBridge(_ref) {
|
|
|
432
540
|
}))();
|
|
433
541
|
return;
|
|
434
542
|
}
|
|
543
|
+
if (message.type === "stopInlineEdit") {
|
|
544
|
+
var _inlineEditing$curren2;
|
|
545
|
+
(_inlineEditing$curren2 = inlineEditing.current) === null || _inlineEditing$curren2 === void 0 || _inlineEditing$curren2.stop();
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (message.type === "focusInlineEdit") {
|
|
549
|
+
var _inlineEditing$curren3;
|
|
550
|
+
(_inlineEditing$curren3 = inlineEditing.current) === null || _inlineEditing$curren3 === void 0 || _inlineEditing$curren3.focus();
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
if (message.type === "applyInlineEdit") {
|
|
554
|
+
// What one of the Studio's controls made of the text being typed
|
|
555
|
+
// in. It replaces what is on the page, so as `editInline`: only
|
|
556
|
+
// from the frame's parent, when that is the Studio here.
|
|
557
|
+
if (event.source !== window.parent) return;
|
|
558
|
+
if (event.origin !== window.location.origin) return;
|
|
559
|
+
var editing = inlineEditing.current;
|
|
560
|
+
if (editing === null || !editing.isActive()) return;
|
|
561
|
+
if (editing.path !== message.path) return;
|
|
562
|
+
editing.apply(message.value, message.selection);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (message.type === "markInlineEdit") {
|
|
566
|
+
// Bold pressed with only a caret: for what is typed next. From the
|
|
567
|
+
// Studio only, as `applyInlineEdit`.
|
|
568
|
+
if (event.source !== window.parent) return;
|
|
569
|
+
if (event.origin !== window.location.origin) return;
|
|
570
|
+
var _editing = inlineEditing.current;
|
|
571
|
+
if (_editing === null || !_editing.isActive()) return;
|
|
572
|
+
if (_editing.path !== message.path) return;
|
|
573
|
+
_editing.mark(message.styles, message.selection);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (message.type === "editInline") {
|
|
577
|
+
var _held$release, _inlineEditing$curren4, _inlineEditing$curren5;
|
|
578
|
+
// A field's words go back as they are typed, unpublished ones
|
|
579
|
+
// included. As `readPage`: only for the frame's parent, when that
|
|
580
|
+
// is the Studio here, and answered to it alone.
|
|
581
|
+
if (event.source !== window.parent) return;
|
|
582
|
+
var _asker4 = event.origin;
|
|
583
|
+
if (_asker4 !== window.location.origin) return;
|
|
584
|
+
var reply = function reply(answer) {
|
|
585
|
+
return window.parent.postMessage(answer, _asker4);
|
|
586
|
+
};
|
|
587
|
+
var pick = lastPick.current;
|
|
588
|
+
lastPick.current = null;
|
|
589
|
+
var held = heldKeys.current;
|
|
590
|
+
heldKeys.current = null;
|
|
591
|
+
var keys = (_held$release = held === null || held === void 0 ? void 0 : held.release()) !== null && _held$release !== void 0 ? _held$release : [];
|
|
592
|
+
// The answer to a click from before the one that started the edit
|
|
593
|
+
// in progress, by itself: that click is what the person did last.
|
|
594
|
+
if (pick === null && startedOnClick.current && ((_inlineEditing$curren4 = inlineEditing.current) === null || _inlineEditing$curren4 === void 0 ? void 0 : _inlineEditing$curren4.isActive()) === true) {
|
|
595
|
+
reply({
|
|
596
|
+
val: VAL_CANVAS_MESSAGE,
|
|
597
|
+
type: "inlineEditUnavailable",
|
|
598
|
+
requestId: message.requestId
|
|
599
|
+
});
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
// One edit at a time, and the element of the last one back as the
|
|
603
|
+
// page has it: it may be the very one asked for again.
|
|
604
|
+
(_inlineEditing$curren5 = inlineEditing.current) === null || _inlineEditing$curren5 === void 0 || _inlineEditing$curren5.release();
|
|
605
|
+
inlineEditing.current = null;
|
|
606
|
+
startedOnClick.current = false;
|
|
607
|
+
var started = startFirst(message.candidates, pick, {
|
|
608
|
+
color: selectionColor.current,
|
|
609
|
+
reply: reply
|
|
610
|
+
});
|
|
611
|
+
if (started !== null) {
|
|
612
|
+
inlineEditing.current = started.editing;
|
|
613
|
+
reply({
|
|
614
|
+
val: VAL_CANVAS_MESSAGE,
|
|
615
|
+
type: "inlineEditStarted",
|
|
616
|
+
requestId: message.requestId,
|
|
617
|
+
path: started.path
|
|
618
|
+
});
|
|
619
|
+
// What was typed while the Studio was being asked, now that
|
|
620
|
+
// there is somewhere for it to go: after `inlineEditStarted`,
|
|
621
|
+
// so the Studio is listening for what it types.
|
|
622
|
+
replayKeys(document, keys);
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
// Nothing on the page shows one of them and nothing else: the
|
|
626
|
+
// Studio opens the field in its own column, and the keys pressed
|
|
627
|
+
// meanwhile are dropped, as on a page that is not being typed in.
|
|
628
|
+
reply({
|
|
629
|
+
val: VAL_CANVAS_MESSAGE,
|
|
630
|
+
type: "inlineEditUnavailable",
|
|
631
|
+
requestId: message.requestId
|
|
632
|
+
});
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
435
635
|
if (message.type === "theme") {
|
|
436
636
|
setSelectionColors({
|
|
437
637
|
selection: message.selection,
|
|
@@ -547,18 +747,85 @@ function ValCanvasBridge(_ref) {
|
|
|
547
747
|
*/
|
|
548
748
|
React.useEffect(function () {
|
|
549
749
|
var onClick = function onClick(event) {
|
|
550
|
-
|
|
750
|
+
var _heldKeys$current2;
|
|
551
751
|
var target = event.target;
|
|
552
752
|
if (!(target instanceof Element)) return;
|
|
753
|
+
// A click in the field being typed in places the caret, and that is
|
|
754
|
+
// all it does: it is neither a pick nor a click on the link or button
|
|
755
|
+
// the text happens to be in. (The caret is the mousedown's, so
|
|
756
|
+
// cancelling the click leaves it where it was put.)
|
|
757
|
+
var editing = inlineEditing.current;
|
|
758
|
+
if (editing !== null && editing.isActive() && editing.contains(target)) {
|
|
759
|
+
event.preventDefault();
|
|
760
|
+
event.stopPropagation();
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
if (!pickingRef.current) return;
|
|
553
764
|
var tagged = target.closest("[data-val-path]");
|
|
554
765
|
var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
|
|
555
|
-
if (!attribute) return;
|
|
766
|
+
if (!tagged || !attribute) return;
|
|
556
767
|
event.preventDefault();
|
|
557
768
|
event.stopPropagation();
|
|
769
|
+
var paths = Internal.splitJoinedSourcePaths(attribute);
|
|
770
|
+
var pick = {
|
|
771
|
+
element: tagged,
|
|
772
|
+
x: event.clientX,
|
|
773
|
+
y: event.clientY
|
|
774
|
+
};
|
|
775
|
+
(_heldKeys$current2 = heldKeys.current) === null || _heldKeys$current2 === void 0 || _heldKeys$current2.release();
|
|
776
|
+
heldKeys.current = null;
|
|
777
|
+
/*
|
|
778
|
+
* Select & edit, and the Studio has said which of this element's
|
|
779
|
+
* fields are texts and what they hold: the edit starts HERE, in the
|
|
780
|
+
* click, rather than a round trip across the frame later. Keys typed
|
|
781
|
+
* straight after the click then go into the text -- in that round
|
|
782
|
+
* trip they went to the page's body, which drops them -- and a phone
|
|
783
|
+
* opens its keyboard, which it does only for a focus given in the tap.
|
|
784
|
+
* Which element shows a field is still decided as `editInline` decides
|
|
785
|
+
* it (`canEditInline`), from the values the Studio sent.
|
|
786
|
+
*/
|
|
787
|
+
var known = textFields.current;
|
|
788
|
+
var offered = known !== null && known.editing ? paths.flatMap(function (path) {
|
|
789
|
+
var _known$editable$get;
|
|
790
|
+
return (_known$editable$get = known.editable.get(path)) !== null && _known$editable$get !== void 0 ? _known$editable$get : [];
|
|
791
|
+
}) : [];
|
|
792
|
+
if (known !== null && offered.length > 0) {
|
|
793
|
+
var _inlineEditing$curren6;
|
|
794
|
+
var reply = function reply(answer) {
|
|
795
|
+
return window.parent.postMessage(answer, known.origin);
|
|
796
|
+
};
|
|
797
|
+
(_inlineEditing$curren6 = inlineEditing.current) === null || _inlineEditing$curren6 === void 0 || _inlineEditing$curren6.release();
|
|
798
|
+
inlineEditing.current = null;
|
|
799
|
+
startedOnClick.current = false;
|
|
800
|
+
var started = startFirst(offered, pick, {
|
|
801
|
+
color: selectionColor.current,
|
|
802
|
+
reply: reply
|
|
803
|
+
});
|
|
804
|
+
if (started !== null) {
|
|
805
|
+
inlineEditing.current = started.editing;
|
|
806
|
+
startedOnClick.current = true;
|
|
807
|
+
lastPick.current = null;
|
|
808
|
+
reply({
|
|
809
|
+
val: VAL_CANVAS_MESSAGE,
|
|
810
|
+
type: "inlineEditStarted",
|
|
811
|
+
requestId: null,
|
|
812
|
+
path: started.path
|
|
813
|
+
});
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
/*
|
|
817
|
+
* A text, but not as the Studio last said: its value changed since
|
|
818
|
+
* (an edit a moment ago, still on its way). The Studio is asked, as
|
|
819
|
+
* for any pick, and the keys pressed until it answers are held
|
|
820
|
+
* rather than lost.
|
|
821
|
+
*/
|
|
822
|
+
heldKeys.current = holdKeys(window);
|
|
823
|
+
}
|
|
824
|
+
lastPick.current = pick;
|
|
558
825
|
post({
|
|
559
826
|
val: VAL_CANVAS_MESSAGE,
|
|
560
827
|
type: "clicked",
|
|
561
|
-
paths:
|
|
828
|
+
paths: paths
|
|
562
829
|
});
|
|
563
830
|
};
|
|
564
831
|
document.addEventListener("click", onClick, {
|
|
@@ -571,6 +838,17 @@ function ValCanvasBridge(_ref) {
|
|
|
571
838
|
};
|
|
572
839
|
}, [post]);
|
|
573
840
|
|
|
841
|
+
// Select off: an emptied text has its room taken away, and keys held for
|
|
842
|
+
// an answer to a pick are dropped. Select on: it has its room again.
|
|
843
|
+
React.useEffect(function () {
|
|
844
|
+
if (!picking) {
|
|
845
|
+
var _heldKeys$current3;
|
|
846
|
+
(_heldKeys$current3 = heldKeys.current) === null || _heldKeys$current3 === void 0 || _heldKeys$current3.release();
|
|
847
|
+
heldKeys.current = null;
|
|
848
|
+
}
|
|
849
|
+
scan();
|
|
850
|
+
}, [picking, scan]);
|
|
851
|
+
|
|
574
852
|
// Esc while picking fields: the key goes to the page, which has the focus
|
|
575
853
|
// once it has been clicked, so the studio hears of it only from here.
|
|
576
854
|
React.useEffect(function () {
|
|
@@ -778,7 +1056,11 @@ function ValCanvasBridge(_ref) {
|
|
|
778
1056
|
// CSS string. A path contains quotes (`?p="/"`) and would otherwise
|
|
779
1057
|
// close the selector early.
|
|
780
1058
|
dangerouslySetInnerHTML: {
|
|
781
|
-
__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, "; }") : "",
|
|
1059
|
+
__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, "; }") : "",
|
|
1060
|
+
// The one rule here that moves the page, and only while Select is
|
|
1061
|
+
// on: an emptied text's line of room, without which it cannot be
|
|
1062
|
+
// pointed at. See `emptyTextFields.ts` for why, and how narrowly.
|
|
1063
|
+
picking ? EMPTY_TEXT_RULES : "", highlighted ? highlightRule(highlighted, selectionColors.selection) : ""].filter(Boolean).join("\n")
|
|
782
1064
|
}
|
|
783
1065
|
});
|
|
784
1066
|
}
|
|
@@ -875,23 +1157,108 @@ function isScrollable(el) {
|
|
|
875
1157
|
};
|
|
876
1158
|
return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
|
|
877
1159
|
}
|
|
1160
|
+
var NO_PATHS = new Set();
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Start editing the first of `candidates` an element on the page shows and
|
|
1164
|
+
* nothing else: the picked element when it carries the candidate's path,
|
|
1165
|
+
* else the first element that does. `null` when none can be.
|
|
1166
|
+
*
|
|
1167
|
+
* What `editInline` does, and what a click does by itself when the Studio has
|
|
1168
|
+
* said ahead of it what the element's texts hold (`textFields`): one way to
|
|
1169
|
+
* start, whichever asked.
|
|
1170
|
+
*/
|
|
1171
|
+
function startFirst(candidates, pick, options) {
|
|
1172
|
+
var reply = options.reply;
|
|
1173
|
+
var _iterator = _createForOfIteratorHelper(candidates),
|
|
1174
|
+
_step;
|
|
1175
|
+
try {
|
|
1176
|
+
var _loop = function _loop() {
|
|
1177
|
+
var candidate = _step.value;
|
|
1178
|
+
var picked = pick !== null && pick.element.isConnected && pathOn(pick.element, candidate.path) !== null ? pick.element : null;
|
|
1179
|
+
var element = picked !== null && picked !== void 0 ? picked : findByPath(candidate.path);
|
|
1180
|
+
if (element === null) return 0; // continue
|
|
1181
|
+
var path = pathOn(element, candidate.path);
|
|
1182
|
+
if (path === null) return 0; // continue
|
|
1183
|
+
var editing = startInlineEditing(element, candidate, {
|
|
1184
|
+
// Where the click was, when it was on this element.
|
|
1185
|
+
at: picked !== null && pick !== null ? {
|
|
1186
|
+
x: pick.x,
|
|
1187
|
+
y: pick.y
|
|
1188
|
+
} : null,
|
|
1189
|
+
color: options.color,
|
|
1190
|
+
onChange: function onChange(value) {
|
|
1191
|
+
return reply({
|
|
1192
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1193
|
+
type: "inlineEdit",
|
|
1194
|
+
path: path,
|
|
1195
|
+
value: value
|
|
1196
|
+
});
|
|
1197
|
+
},
|
|
1198
|
+
onEnd: function onEnd() {
|
|
1199
|
+
return reply({
|
|
1200
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1201
|
+
type: "inlineEditEnded",
|
|
1202
|
+
path: path
|
|
1203
|
+
});
|
|
1204
|
+
},
|
|
1205
|
+
onSelection: function onSelection(selection, rect, caret) {
|
|
1206
|
+
return reply({
|
|
1207
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1208
|
+
type: "inlineEditSelection",
|
|
1209
|
+
path: path,
|
|
1210
|
+
selection: selection,
|
|
1211
|
+
rect: rect,
|
|
1212
|
+
caret: caret
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
if (editing !== null) return {
|
|
1217
|
+
v: {
|
|
1218
|
+
editing: editing,
|
|
1219
|
+
path: path
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
},
|
|
1223
|
+
_ret;
|
|
1224
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1225
|
+
_ret = _loop();
|
|
1226
|
+
if (_ret === 0) continue;
|
|
1227
|
+
if (_ret) return _ret.v;
|
|
1228
|
+
}
|
|
1229
|
+
} catch (err) {
|
|
1230
|
+
_iterator.e(err);
|
|
1231
|
+
} finally {
|
|
1232
|
+
_iterator.f();
|
|
1233
|
+
}
|
|
1234
|
+
return null;
|
|
1235
|
+
}
|
|
878
1236
|
function findByPath(path) {
|
|
879
1237
|
var elements = document.querySelectorAll("[data-val-path]");
|
|
880
1238
|
for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
|
|
881
1239
|
var el = _Array$from[_i];
|
|
882
|
-
|
|
883
|
-
if (!attribute) continue;
|
|
884
|
-
// Compared as strings: the split returns branded `SourcePath`s and what
|
|
885
|
-
// came back over `postMessage` is a plain string, which is the same value.
|
|
886
|
-
if (Internal.splitJoinedSourcePaths(attribute).some(function (candidate) {
|
|
887
|
-
return candidate === path;
|
|
888
|
-
})) {
|
|
889
|
-
return el;
|
|
890
|
-
}
|
|
1240
|
+
if (pathOn(el, path) !== null) return el;
|
|
891
1241
|
}
|
|
892
1242
|
return null;
|
|
893
1243
|
}
|
|
894
1244
|
|
|
1245
|
+
/**
|
|
1246
|
+
* `path` as `element` carries it, or null when it does not.
|
|
1247
|
+
*
|
|
1248
|
+
* Compared as strings: the split returns branded `SourcePath`s and what came
|
|
1249
|
+
* back over `postMessage` is a plain string, which is the same value. What is
|
|
1250
|
+
* returned is the element's own, so it is a `SourcePath` without anyone
|
|
1251
|
+
* having to say so.
|
|
1252
|
+
*/
|
|
1253
|
+
function pathOn(element, path) {
|
|
1254
|
+
var _Internal$splitJoined;
|
|
1255
|
+
var attribute = element.getAttribute("data-val-path");
|
|
1256
|
+
if (!attribute) return null;
|
|
1257
|
+
return (_Internal$splitJoined = Internal.splitJoinedSourcePaths(attribute).find(function (candidate) {
|
|
1258
|
+
return candidate === path;
|
|
1259
|
+
})) !== null && _Internal$splitJoined !== void 0 ? _Internal$splitJoined : null;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
895
1262
|
/** What `screenshotPage` answers: the picture, or why it could not be taken. */
|
|
896
1263
|
function screenshotReply(_x) {
|
|
897
1264
|
return _screenshotReply.apply(this, arguments);
|