@valbuild/next 0.153.5 → 0.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/dist/ValCanvasBridge-063ad333.cjs.js +7 -0
- package/dist/{ValCanvasBridge-50bf5366.cjs.prod.js → ValCanvasBridge-063ad333.cjs.prod.js} +453 -23
- package/dist/{ValCanvasBridge-cf8d7967.esm.js → ValCanvasBridge-719e6efe.esm.js} +454 -24
- package/dist/{ValCanvasBridge-fc46ab88.cjs.dev.js → ValCanvasBridge-9b2df334.cjs.dev.js} +453 -23
- package/dist/{ValNextProvider-b4eae85e.esm.js → ValNextProvider-27242758.esm.js} +15 -2
- package/dist/{ValNextProvider-5e29689e.cjs.dev.js → ValNextProvider-4838fed0.cjs.dev.js} +14 -1
- package/dist/ValNextProvider-9343dc1e.cjs.js +7 -0
- package/dist/{ValNextProvider-06854ec0.cjs.prod.js → ValNextProvider-9343dc1e.cjs.prod.js} +14 -1
- package/dist/valbuild-next.cjs.dev.js +2 -2
- package/dist/valbuild-next.cjs.prod.js +2 -2
- package/dist/valbuild-next.esm.js +2 -2
- package/dist/{version-a7fe5cf9.cjs.prod.js → version-4d44d9cd.cjs.prod.js} +1 -1
- package/dist/{version-ac0839be.cjs.dev.js → version-93ae5f54.cjs.dev.js} +1 -1
- package/dist/{version-32b03e4b.esm.js → version-9adeab58.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-50bf5366.cjs.js +0 -7
- package/dist/ValNextProvider-06854ec0.cjs.js +0 -7
|
@@ -1,11 +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, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, isValCanvasStudioMessage, restoreScroll, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, isCodeChangedDetail, screenshotPage, readPageSnapshot } from '@valbuild/shared/client';
|
|
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-9adeab58.esm.js';
|
|
9
11
|
import { jsx } from 'react/jsx-runtime';
|
|
10
12
|
|
|
11
13
|
function _arrayWithoutHoles(r) {
|
|
@@ -38,6 +40,13 @@ var DEFAULT_SELECTION = {
|
|
|
38
40
|
*/
|
|
39
41
|
var RESCAN_INTERVAL_MS = 5000;
|
|
40
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
|
+
|
|
41
50
|
/**
|
|
42
51
|
* The page's half of the canvas protocol.
|
|
43
52
|
*
|
|
@@ -102,6 +111,50 @@ function ValCanvasBridge(_ref) {
|
|
|
102
111
|
return (_stopRestoring$curren = stopRestoring.current) === null || _stopRestoring$curren === void 0 ? void 0 : _stopRestoring$curren.call(stopRestoring);
|
|
103
112
|
};
|
|
104
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;
|
|
105
158
|
var post = React.useCallback(function (message) {
|
|
106
159
|
// `*` as the target origin: the studio and the page share an origin today,
|
|
107
160
|
// but the frame does not know the parent's origin for certain and naming
|
|
@@ -123,6 +176,10 @@ function ValCanvasBridge(_ref) {
|
|
|
123
176
|
|
|
124
177
|
/** Every element Val tagged, with where it is on the page. */
|
|
125
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);
|
|
126
183
|
var elements = [];
|
|
127
184
|
var scrollX = window.scrollX;
|
|
128
185
|
var scrollY = window.scrollY;
|
|
@@ -200,7 +257,7 @@ function ValCanvasBridge(_ref) {
|
|
|
200
257
|
|
|
201
258
|
// Announce the frame, and say whether it is actually showing draft content.
|
|
202
259
|
React.useEffect(function () {
|
|
203
|
-
post(_objectSpread2(_objectSpread2({
|
|
260
|
+
post(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
204
261
|
val: VAL_CANVAS_MESSAGE,
|
|
205
262
|
type: "ready",
|
|
206
263
|
draftMode: draftMode,
|
|
@@ -209,7 +266,16 @@ function ValCanvasBridge(_ref) {
|
|
|
209
266
|
holds: _toConsumableArray(holds)
|
|
210
267
|
} : {}), holdsVersions !== undefined && Object.keys(holdsVersions).length > 0 ? {
|
|
211
268
|
holdsVersions: holdsVersions
|
|
212
|
-
} : {})
|
|
269
|
+
} : {}), {}, {
|
|
270
|
+
// What this bridge answers, so the Studio never waits on a request
|
|
271
|
+
// it would not: see `capabilities` in the protocol.
|
|
272
|
+
capabilities: _toConsumableArray(BRIDGE_CAPABILITIES),
|
|
273
|
+
document: DOCUMENT_ID,
|
|
274
|
+
bridge: {
|
|
275
|
+
"package": "@valbuild/next",
|
|
276
|
+
version: VERSION
|
|
277
|
+
}
|
|
278
|
+
}));
|
|
213
279
|
}, [post, draftMode, holds, holdsVersions]);
|
|
214
280
|
|
|
215
281
|
/**
|
|
@@ -322,6 +388,22 @@ function ValCanvasBridge(_ref) {
|
|
|
322
388
|
setPicking(message.picking);
|
|
323
389
|
return;
|
|
324
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
|
+
}
|
|
325
407
|
if (message.type === "pickElements") {
|
|
326
408
|
var _message$color;
|
|
327
409
|
setElementPicking({
|
|
@@ -354,15 +436,60 @@ function ValCanvasBridge(_ref) {
|
|
|
354
436
|
window.parent.postMessage(readPageReply(message), asker);
|
|
355
437
|
return;
|
|
356
438
|
}
|
|
439
|
+
if (message.type === "readPageLog") {
|
|
440
|
+
// The assistant's `read_page_log`: what the page logged as going
|
|
441
|
+
// wrong. As `readPage`: only for the frame's parent, when that is
|
|
442
|
+
// the Studio here, and answered to it alone.
|
|
443
|
+
if (event.source !== window.parent) return;
|
|
444
|
+
var _asker = event.origin;
|
|
445
|
+
if (_asker !== window.location.origin) return;
|
|
446
|
+
window.parent.postMessage(readPageLogReply(message), _asker);
|
|
447
|
+
return;
|
|
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
|
+
}
|
|
357
484
|
if (message.type === "screenshotPage") {
|
|
358
485
|
// The assistant's `screenshot_page`: a picture of the page, drawn
|
|
359
486
|
// here. As `readPage`: only for the frame's parent, when that is the
|
|
360
487
|
// Studio here, and answered to it alone.
|
|
361
488
|
if (event.source !== window.parent) return;
|
|
362
|
-
var
|
|
363
|
-
if (
|
|
489
|
+
var _asker3 = event.origin;
|
|
490
|
+
if (_asker3 !== window.location.origin) return;
|
|
364
491
|
void screenshotReply(message).then(function (reply) {
|
|
365
|
-
return window.parent.postMessage(reply,
|
|
492
|
+
return window.parent.postMessage(reply, _asker3);
|
|
366
493
|
});
|
|
367
494
|
return;
|
|
368
495
|
}
|
|
@@ -413,6 +540,98 @@ function ValCanvasBridge(_ref) {
|
|
|
413
540
|
}))();
|
|
414
541
|
return;
|
|
415
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
|
+
}
|
|
416
635
|
if (message.type === "theme") {
|
|
417
636
|
setSelectionColors({
|
|
418
637
|
selection: message.selection,
|
|
@@ -501,10 +720,17 @@ function ValCanvasBridge(_ref) {
|
|
|
501
720
|
};
|
|
502
721
|
}, [codeChanged, post]);
|
|
503
722
|
|
|
504
|
-
//
|
|
723
|
+
// The page's log, if the provider's module did not start it already.
|
|
724
|
+
React.useEffect(function () {
|
|
725
|
+
pageLog();
|
|
726
|
+
}, []);
|
|
727
|
+
|
|
728
|
+
// Where the page is, as it moves: a new build is opened there. The log
|
|
729
|
+
// hears of it too, so a client-side navigation starts a new page in it.
|
|
505
730
|
React.useEffect(function () {
|
|
506
731
|
return watchPageLocation(window, function (location) {
|
|
507
|
-
|
|
732
|
+
pageLog().noteLocation();
|
|
733
|
+
post(_objectSpread2({
|
|
508
734
|
val: VAL_CANVAS_MESSAGE,
|
|
509
735
|
type: "location"
|
|
510
736
|
}, location));
|
|
@@ -521,18 +747,85 @@ function ValCanvasBridge(_ref) {
|
|
|
521
747
|
*/
|
|
522
748
|
React.useEffect(function () {
|
|
523
749
|
var onClick = function onClick(event) {
|
|
524
|
-
|
|
750
|
+
var _heldKeys$current2;
|
|
525
751
|
var target = event.target;
|
|
526
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;
|
|
527
764
|
var tagged = target.closest("[data-val-path]");
|
|
528
765
|
var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
|
|
529
|
-
if (!attribute) return;
|
|
766
|
+
if (!tagged || !attribute) return;
|
|
530
767
|
event.preventDefault();
|
|
531
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;
|
|
532
825
|
post({
|
|
533
826
|
val: VAL_CANVAS_MESSAGE,
|
|
534
827
|
type: "clicked",
|
|
535
|
-
paths:
|
|
828
|
+
paths: paths
|
|
536
829
|
});
|
|
537
830
|
};
|
|
538
831
|
document.addEventListener("click", onClick, {
|
|
@@ -545,6 +838,17 @@ function ValCanvasBridge(_ref) {
|
|
|
545
838
|
};
|
|
546
839
|
}, [post]);
|
|
547
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
|
+
|
|
548
852
|
// Esc while picking fields: the key goes to the page, which has the focus
|
|
549
853
|
// once it has been clicked, so the studio hears of it only from here.
|
|
550
854
|
React.useEffect(function () {
|
|
@@ -752,7 +1056,11 @@ function ValCanvasBridge(_ref) {
|
|
|
752
1056
|
// CSS string. A path contains quotes (`?p="/"`) and would otherwise
|
|
753
1057
|
// close the selector early.
|
|
754
1058
|
dangerouslySetInnerHTML: {
|
|
755
|
-
__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")
|
|
756
1064
|
}
|
|
757
1065
|
});
|
|
758
1066
|
}
|
|
@@ -849,28 +1157,118 @@ function isScrollable(el) {
|
|
|
849
1157
|
};
|
|
850
1158
|
return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
|
|
851
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
|
+
}
|
|
852
1236
|
function findByPath(path) {
|
|
853
1237
|
var elements = document.querySelectorAll("[data-val-path]");
|
|
854
1238
|
for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
|
|
855
1239
|
var el = _Array$from[_i];
|
|
856
|
-
|
|
857
|
-
if (!attribute) continue;
|
|
858
|
-
// Compared as strings: the split returns branded `SourcePath`s and what
|
|
859
|
-
// came back over `postMessage` is a plain string, which is the same value.
|
|
860
|
-
if (Internal.splitJoinedSourcePaths(attribute).some(function (candidate) {
|
|
861
|
-
return candidate === path;
|
|
862
|
-
})) {
|
|
863
|
-
return el;
|
|
864
|
-
}
|
|
1240
|
+
if (pathOn(el, path) !== null) return el;
|
|
865
1241
|
}
|
|
866
1242
|
return null;
|
|
867
1243
|
}
|
|
868
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
|
+
|
|
869
1262
|
/** What `screenshotPage` answers: the picture, or why it could not be taken. */
|
|
870
1263
|
function screenshotReply(_x) {
|
|
871
1264
|
return _screenshotReply.apply(this, arguments);
|
|
872
1265
|
}
|
|
873
|
-
/**
|
|
1266
|
+
/**
|
|
1267
|
+
* The page's log (`pageLog.ts`). Started when the provider's module was
|
|
1268
|
+
* evaluated in the canvas, before hydration; started here, as late as the
|
|
1269
|
+
* bridge mounts, only if that did not happen -- a document that was not the
|
|
1270
|
+
* canvas when the provider loaded (see `isValCanvasFrame`).
|
|
1271
|
+
*/
|
|
874
1272
|
function _screenshotReply() {
|
|
875
1273
|
_screenshotReply = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(message) {
|
|
876
1274
|
var _t2, _t3, _t4, _t5;
|
|
@@ -912,17 +1310,49 @@ function _screenshotReply() {
|
|
|
912
1310
|
}));
|
|
913
1311
|
return _screenshotReply.apply(this, arguments);
|
|
914
1312
|
}
|
|
1313
|
+
function pageLog() {
|
|
1314
|
+
return installPageLog(window);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
/** What `readPageLog` answers: the page's log, or why it could not be read. */
|
|
1318
|
+
function readPageLogReply(message) {
|
|
1319
|
+
try {
|
|
1320
|
+
return {
|
|
1321
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1322
|
+
type: "pageLogRead",
|
|
1323
|
+
requestId: message.requestId,
|
|
1324
|
+
log: pageLog().read(_objectSpread2(_objectSpread2({}, message.sinceNavigation !== undefined ? {
|
|
1325
|
+
sinceNavigation: message.sinceNavigation
|
|
1326
|
+
} : {}), message.levels !== undefined ? {
|
|
1327
|
+
levels: message.levels
|
|
1328
|
+
} : {}))
|
|
1329
|
+
};
|
|
1330
|
+
} catch (error) {
|
|
1331
|
+
return {
|
|
1332
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1333
|
+
type: "pageLogRead",
|
|
1334
|
+
requestId: message.requestId,
|
|
1335
|
+
log: null,
|
|
1336
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
/** What `readPage` answers: the page read, or why it could not be. */
|
|
915
1342
|
function readPageReply(message) {
|
|
916
1343
|
try {
|
|
917
1344
|
return {
|
|
918
1345
|
val: VAL_CANVAS_MESSAGE,
|
|
919
1346
|
type: "pageRead",
|
|
920
1347
|
requestId: message.requestId,
|
|
921
|
-
snapshot: readPageSnapshot(document, _objectSpread2(_objectSpread2({}, message.selector !== undefined ? {
|
|
1348
|
+
snapshot: _objectSpread2(_objectSpread2({}, readPageSnapshot(document, _objectSpread2(_objectSpread2({}, message.selector !== undefined ? {
|
|
922
1349
|
selector: message.selector
|
|
923
1350
|
} : {}), message.maxItems !== undefined ? {
|
|
924
1351
|
maxItems: message.maxItems
|
|
925
|
-
} : {}))
|
|
1352
|
+
} : {}))), {}, {
|
|
1353
|
+
// So the assistant notices the page threw without asking.
|
|
1354
|
+
log: pageLog().counts()
|
|
1355
|
+
})
|
|
926
1356
|
};
|
|
927
1357
|
} catch (error) {
|
|
928
1358
|
return {
|