@valbuild/tanstack 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/valbuild-tanstack.cjs.dev.js +465 -24
- package/dist/valbuild-tanstack.cjs.prod.js +465 -24
- package/dist/valbuild-tanstack.esm.js +466 -25
- package/dist/{version-fb089780.cjs.dev.js → version-208d50df.cjs.dev.js} +1 -1
- package/dist/{version-05a3822d.esm.js → version-59dbc545.esm.js} +1 -1
- package/dist/{version-cc68a2d8.cjs.prod.js → version-961b447c.cjs.prod.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
|
@@ -5,14 +5,14 @@ import * as core from '@valbuild/core';
|
|
|
5
5
|
export { core as expr };
|
|
6
6
|
export { GenericSelector, Schema, VAL_EXTENSION, derefPatch, modules } from '@valbuild/core';
|
|
7
7
|
import { stegaEncode, stegaDecodeStrings, attrs, raw, isReactDevelopmentBuild, watchStegaLeaks, stegaLeakMessage, SET_AUTO_TAG_JSX_ENABLED, autoTagJSX } from '@valbuild/react/stega';
|
|
8
|
-
import { r as readValEnableCookie, V as VERSION$1 } from './version-
|
|
8
|
+
import { r as readValEnableCookie, V as VERSION$1 } from './version-59dbc545.esm.js';
|
|
9
9
|
import { isDraft, windowCodeChangedReporter, createDraftStore, draftHolds, draftHoldsVersions, startRefreshLoop, dispatchCodeChanged, applyValEvent } from '@valbuild/react/internal';
|
|
10
10
|
export { ValRichText } from '@valbuild/react/internal';
|
|
11
11
|
import { VERSION, VAL_APP_PATH, VAL_OVERLAY_ID, VAL_APP_ID } from '@valbuild/ui';
|
|
12
12
|
import { useRouter, useRouterState } from '@tanstack/react-router';
|
|
13
13
|
import React, { useEffect, useRef, useState } from 'react';
|
|
14
14
|
import { V as ValOverlayProvider } from './ValOverlayContext-bd2f453c.esm.js';
|
|
15
|
-
import { VAL_CONFIG_SESSION_STORAGE_KEY, VAL_THEME_SESSION_STORAGE_KEY, VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, isValCanvasStudioMessage, restoreScroll, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, isCodeChangedDetail, screenshotPage, readPageSnapshot, isValCanvasFrame } from '@valbuild/shared/client';
|
|
15
|
+
import { VAL_CONFIG_SESSION_STORAGE_KEY, VAL_THEME_SESSION_STORAGE_KEY, markEmptyTextFields, VAL_CANVAS_MESSAGE, watchPageLocation, startElementPicking, EMPTY_TEXT_RULES, installPageLog, DEFAULT_CANVAS_SELECTION, DEFAULT_CANVAS_SELECTION_SOFT, BRIDGE_CAPABILITIES, isValCanvasStudioMessage, restoreScroll, interactWithPage, storeQuickPreview, QUICK_PREVIEW_SERVICE_WORKER_PATH, replayKeys, isCodeChangedDetail, holdKeys, startInlineEditing, screenshotPage, readPageSnapshot, installPageLogInCanvasFrame, isValCanvasFrame } from '@valbuild/shared/client';
|
|
16
16
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
17
17
|
import { D as DEMO_CLAIM_MESSAGE, a as DEMO_SERVICE_WORKER_PATH, b as DEMO_RELAY_MESSAGE } from './demoServiceWorker-56fd96cf.esm.js';
|
|
18
18
|
|
|
@@ -240,6 +240,13 @@ var DEFAULT_SELECTION = {
|
|
|
240
240
|
*/
|
|
241
241
|
var RESCAN_INTERVAL_MS = 5000;
|
|
242
242
|
|
|
243
|
+
/**
|
|
244
|
+
* This document, among the ones the frame loads: sent with every `ready`
|
|
245
|
+
* (see `document` there). Made when the module is evaluated, which is once
|
|
246
|
+
* per document. Not `crypto.randomUUID`, which an insecure context lacks.
|
|
247
|
+
*/
|
|
248
|
+
var DOCUMENT_ID = "".concat(Date.now().toString(36), "-").concat(Math.random().toString(36).slice(2));
|
|
249
|
+
|
|
243
250
|
/**
|
|
244
251
|
* The page's half of the canvas protocol.
|
|
245
252
|
*
|
|
@@ -304,6 +311,50 @@ function ValCanvasBridge(_ref) {
|
|
|
304
311
|
return (_stopRestoring$curren = stopRestoring.current) === null || _stopRestoring$curren === void 0 ? void 0 : _stopRestoring$curren.call(stopRestoring);
|
|
305
312
|
};
|
|
306
313
|
}, []);
|
|
314
|
+
/**
|
|
315
|
+
* The field being edited on the page itself (`editInline`), or the last
|
|
316
|
+
* one that was, while its copy waits for the page to catch up. See
|
|
317
|
+
* `inlineEditing.ts` in `@valbuild/shared`, which both bindings run.
|
|
318
|
+
*/
|
|
319
|
+
var inlineEditing = React.useRef(null);
|
|
320
|
+
React.useEffect(function () {
|
|
321
|
+
return function () {
|
|
322
|
+
var _inlineEditing$curren;
|
|
323
|
+
return (_inlineEditing$curren = inlineEditing.current) === null || _inlineEditing$curren === void 0 ? void 0 : _inlineEditing$curren.release();
|
|
324
|
+
};
|
|
325
|
+
}, []);
|
|
326
|
+
/**
|
|
327
|
+
* The last pick: the element and where on it. `editInline` is the Studio's
|
|
328
|
+
* answer to a `clicked`, and the caret belongs where that click was.
|
|
329
|
+
*/
|
|
330
|
+
var lastPick = React.useRef(null);
|
|
331
|
+
/**
|
|
332
|
+
* The page's texts as the Studio last said (`textFields`), and the origin
|
|
333
|
+
* that said it, which is the only one an edit started from them answers.
|
|
334
|
+
* `null` until it says: a Studio that predates it never does, and every
|
|
335
|
+
* click then asks, as before.
|
|
336
|
+
*/
|
|
337
|
+
var textFields = React.useRef(null);
|
|
338
|
+
/**
|
|
339
|
+
* Whether the edit in progress was started here, in a click, rather than
|
|
340
|
+
* by `editInline`: an `editInline` that arrives after it answers a click
|
|
341
|
+
* from before it, and must not take the caret away.
|
|
342
|
+
*/
|
|
343
|
+
var startedOnClick = React.useRef(false);
|
|
344
|
+
/**
|
|
345
|
+
* The keys pressed since a click the Studio was asked about, until it
|
|
346
|
+
* answers: see `inlineEditKeys.ts`.
|
|
347
|
+
*/
|
|
348
|
+
var heldKeys = React.useRef(null);
|
|
349
|
+
React.useEffect(function () {
|
|
350
|
+
return function () {
|
|
351
|
+
var _heldKeys$current;
|
|
352
|
+
(_heldKeys$current = heldKeys.current) === null || _heldKeys$current === void 0 || _heldKeys$current.release();
|
|
353
|
+
};
|
|
354
|
+
}, []);
|
|
355
|
+
// Read when an edit starts, long after the render that set it.
|
|
356
|
+
var selectionColor = React.useRef(selectionColors.selection);
|
|
357
|
+
selectionColor.current = selectionColors.selection;
|
|
307
358
|
var post = React.useCallback(function (message) {
|
|
308
359
|
// `*` as the target origin: the studio and the page share an origin today,
|
|
309
360
|
// but the frame does not know the parent's origin for certain and naming
|
|
@@ -325,6 +376,10 @@ function ValCanvasBridge(_ref) {
|
|
|
325
376
|
|
|
326
377
|
/** Every element Val tagged, with where it is on the page. */
|
|
327
378
|
var scan = React.useCallback(function () {
|
|
379
|
+
var _textFields$current$e, _textFields$current;
|
|
380
|
+
// Before measuring: an emptied text measures with the room it is given
|
|
381
|
+
// while Select is on, so the Studio's outline of it has a size too.
|
|
382
|
+
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$1.splitJoinedSourcePaths);
|
|
328
383
|
var elements = [];
|
|
329
384
|
var scrollX = window.scrollX;
|
|
330
385
|
var scrollY = window.scrollY;
|
|
@@ -402,7 +457,7 @@ function ValCanvasBridge(_ref) {
|
|
|
402
457
|
|
|
403
458
|
// Announce the frame, and say whether it is actually showing draft content.
|
|
404
459
|
React.useEffect(function () {
|
|
405
|
-
post(_objectSpread2(_objectSpread2({
|
|
460
|
+
post(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
406
461
|
val: VAL_CANVAS_MESSAGE,
|
|
407
462
|
type: "ready",
|
|
408
463
|
draftMode: draftMode,
|
|
@@ -411,7 +466,16 @@ function ValCanvasBridge(_ref) {
|
|
|
411
466
|
holds: _toConsumableArray(holds)
|
|
412
467
|
} : {}), holdsVersions !== undefined && Object.keys(holdsVersions).length > 0 ? {
|
|
413
468
|
holdsVersions: holdsVersions
|
|
414
|
-
} : {})
|
|
469
|
+
} : {}), {}, {
|
|
470
|
+
// What this bridge answers, so the Studio never waits on a request
|
|
471
|
+
// it would not: see `capabilities` in the protocol.
|
|
472
|
+
capabilities: _toConsumableArray(BRIDGE_CAPABILITIES),
|
|
473
|
+
document: DOCUMENT_ID,
|
|
474
|
+
bridge: {
|
|
475
|
+
"package": "@valbuild/tanstack",
|
|
476
|
+
version: VERSION$1
|
|
477
|
+
}
|
|
478
|
+
}));
|
|
415
479
|
}, [post, draftMode, holds, holdsVersions]);
|
|
416
480
|
|
|
417
481
|
/**
|
|
@@ -524,6 +588,22 @@ function ValCanvasBridge(_ref) {
|
|
|
524
588
|
setPicking(message.picking);
|
|
525
589
|
return;
|
|
526
590
|
}
|
|
591
|
+
if (message.type === "textFields") {
|
|
592
|
+
// What starts an edit on a click, so as `editInline`: only from the
|
|
593
|
+
// frame's parent, when that is the Studio here.
|
|
594
|
+
if (event.source !== window.parent) return;
|
|
595
|
+
if (event.origin !== window.location.origin) return;
|
|
596
|
+
textFields.current = {
|
|
597
|
+
editing: message.editing,
|
|
598
|
+
editable: new Map(message.editable.map(function (candidate) {
|
|
599
|
+
return [candidate.path, candidate];
|
|
600
|
+
})),
|
|
601
|
+
empty: new Set(message.empty),
|
|
602
|
+
origin: event.origin
|
|
603
|
+
};
|
|
604
|
+
scan();
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
527
607
|
if (message.type === "pickElements") {
|
|
528
608
|
var _message$color;
|
|
529
609
|
setElementPicking({
|
|
@@ -556,15 +636,60 @@ function ValCanvasBridge(_ref) {
|
|
|
556
636
|
window.parent.postMessage(readPageReply(message), asker);
|
|
557
637
|
return;
|
|
558
638
|
}
|
|
639
|
+
if (message.type === "readPageLog") {
|
|
640
|
+
// The assistant's `read_page_log`: what the page logged as going
|
|
641
|
+
// wrong. As `readPage`: only for the frame's parent, when that is
|
|
642
|
+
// the Studio here, and answered to it alone.
|
|
643
|
+
if (event.source !== window.parent) return;
|
|
644
|
+
var _asker = event.origin;
|
|
645
|
+
if (_asker !== window.location.origin) return;
|
|
646
|
+
window.parent.postMessage(readPageLogReply(message), _asker);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
if (message.type === "interact") {
|
|
650
|
+
// The assistant's `interact_page`: do something on the page and
|
|
651
|
+
// read it once it settled (`pageInteraction.ts`) -- a click or
|
|
652
|
+
// Enter/Space only once the person allowed it. As
|
|
653
|
+
// `readPage`: only for the frame's parent, when that is the Studio
|
|
654
|
+
// here, and answered to it alone.
|
|
655
|
+
if (event.source !== window.parent) return;
|
|
656
|
+
var _asker2 = event.origin;
|
|
657
|
+
if (_asker2 !== window.location.origin) return;
|
|
658
|
+
var requestId = message.requestId;
|
|
659
|
+
void interactWithPage(window, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
660
|
+
action: message.action
|
|
661
|
+
}, message.maxItems !== undefined ? {
|
|
662
|
+
maxItems: message.maxItems
|
|
663
|
+
} : {}), message.timeoutMs !== undefined ? {
|
|
664
|
+
timeoutMs: message.timeoutMs
|
|
665
|
+
} : {}), message.logFrom !== undefined ? {
|
|
666
|
+
logFrom: message.logFrom
|
|
667
|
+
} : {}), message.approved !== undefined ? {
|
|
668
|
+
approved: message.approved
|
|
669
|
+
} : {}), {}, {
|
|
670
|
+
document: DOCUMENT_ID
|
|
671
|
+
}), pageLog()).then(function (outcome) {
|
|
672
|
+
var answer = {
|
|
673
|
+
val: VAL_CANVAS_MESSAGE,
|
|
674
|
+
type: "interacted",
|
|
675
|
+
requestId: requestId,
|
|
676
|
+
outcome: outcome,
|
|
677
|
+
// Which document answered: see `interacted` in the protocol.
|
|
678
|
+
document: DOCUMENT_ID
|
|
679
|
+
};
|
|
680
|
+
window.parent.postMessage(answer, _asker2);
|
|
681
|
+
});
|
|
682
|
+
return;
|
|
683
|
+
}
|
|
559
684
|
if (message.type === "screenshotPage") {
|
|
560
685
|
// The assistant's `screenshot_page`: a picture of the page, drawn
|
|
561
686
|
// here. As `readPage`: only for the frame's parent, when that is the
|
|
562
687
|
// Studio here, and answered to it alone.
|
|
563
688
|
if (event.source !== window.parent) return;
|
|
564
|
-
var
|
|
565
|
-
if (
|
|
689
|
+
var _asker3 = event.origin;
|
|
690
|
+
if (_asker3 !== window.location.origin) return;
|
|
566
691
|
void screenshotReply(message).then(function (reply) {
|
|
567
|
-
return window.parent.postMessage(reply,
|
|
692
|
+
return window.parent.postMessage(reply, _asker3);
|
|
568
693
|
});
|
|
569
694
|
return;
|
|
570
695
|
}
|
|
@@ -615,6 +740,98 @@ function ValCanvasBridge(_ref) {
|
|
|
615
740
|
}))();
|
|
616
741
|
return;
|
|
617
742
|
}
|
|
743
|
+
if (message.type === "stopInlineEdit") {
|
|
744
|
+
var _inlineEditing$curren2;
|
|
745
|
+
(_inlineEditing$curren2 = inlineEditing.current) === null || _inlineEditing$curren2 === void 0 || _inlineEditing$curren2.stop();
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
if (message.type === "focusInlineEdit") {
|
|
749
|
+
var _inlineEditing$curren3;
|
|
750
|
+
(_inlineEditing$curren3 = inlineEditing.current) === null || _inlineEditing$curren3 === void 0 || _inlineEditing$curren3.focus();
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (message.type === "applyInlineEdit") {
|
|
754
|
+
// What one of the Studio's controls made of the text being typed
|
|
755
|
+
// in. It replaces what is on the page, so as `editInline`: only
|
|
756
|
+
// from the frame's parent, when that is the Studio here.
|
|
757
|
+
if (event.source !== window.parent) return;
|
|
758
|
+
if (event.origin !== window.location.origin) return;
|
|
759
|
+
var editing = inlineEditing.current;
|
|
760
|
+
if (editing === null || !editing.isActive()) return;
|
|
761
|
+
if (editing.path !== message.path) return;
|
|
762
|
+
editing.apply(message.value, message.selection);
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
if (message.type === "markInlineEdit") {
|
|
766
|
+
// Bold pressed with only a caret: for what is typed next. From the
|
|
767
|
+
// Studio only, as `applyInlineEdit`.
|
|
768
|
+
if (event.source !== window.parent) return;
|
|
769
|
+
if (event.origin !== window.location.origin) return;
|
|
770
|
+
var _editing = inlineEditing.current;
|
|
771
|
+
if (_editing === null || !_editing.isActive()) return;
|
|
772
|
+
if (_editing.path !== message.path) return;
|
|
773
|
+
_editing.mark(message.styles, message.selection);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
if (message.type === "editInline") {
|
|
777
|
+
var _held$release, _inlineEditing$curren4, _inlineEditing$curren5;
|
|
778
|
+
// A field's words go back as they are typed, unpublished ones
|
|
779
|
+
// included. As `readPage`: only for the frame's parent, when that
|
|
780
|
+
// is the Studio here, and answered to it alone.
|
|
781
|
+
if (event.source !== window.parent) return;
|
|
782
|
+
var _asker4 = event.origin;
|
|
783
|
+
if (_asker4 !== window.location.origin) return;
|
|
784
|
+
var reply = function reply(answer) {
|
|
785
|
+
return window.parent.postMessage(answer, _asker4);
|
|
786
|
+
};
|
|
787
|
+
var pick = lastPick.current;
|
|
788
|
+
lastPick.current = null;
|
|
789
|
+
var held = heldKeys.current;
|
|
790
|
+
heldKeys.current = null;
|
|
791
|
+
var keys = (_held$release = held === null || held === void 0 ? void 0 : held.release()) !== null && _held$release !== void 0 ? _held$release : [];
|
|
792
|
+
// The answer to a click from before the one that started the edit
|
|
793
|
+
// in progress, by itself: that click is what the person did last.
|
|
794
|
+
if (pick === null && startedOnClick.current && ((_inlineEditing$curren4 = inlineEditing.current) === null || _inlineEditing$curren4 === void 0 ? void 0 : _inlineEditing$curren4.isActive()) === true) {
|
|
795
|
+
reply({
|
|
796
|
+
val: VAL_CANVAS_MESSAGE,
|
|
797
|
+
type: "inlineEditUnavailable",
|
|
798
|
+
requestId: message.requestId
|
|
799
|
+
});
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
// One edit at a time, and the element of the last one back as the
|
|
803
|
+
// page has it: it may be the very one asked for again.
|
|
804
|
+
(_inlineEditing$curren5 = inlineEditing.current) === null || _inlineEditing$curren5 === void 0 || _inlineEditing$curren5.release();
|
|
805
|
+
inlineEditing.current = null;
|
|
806
|
+
startedOnClick.current = false;
|
|
807
|
+
var started = startFirst(message.candidates, pick, {
|
|
808
|
+
color: selectionColor.current,
|
|
809
|
+
reply: reply
|
|
810
|
+
});
|
|
811
|
+
if (started !== null) {
|
|
812
|
+
inlineEditing.current = started.editing;
|
|
813
|
+
reply({
|
|
814
|
+
val: VAL_CANVAS_MESSAGE,
|
|
815
|
+
type: "inlineEditStarted",
|
|
816
|
+
requestId: message.requestId,
|
|
817
|
+
path: started.path
|
|
818
|
+
});
|
|
819
|
+
// What was typed while the Studio was being asked, now that
|
|
820
|
+
// there is somewhere for it to go: after `inlineEditStarted`,
|
|
821
|
+
// so the Studio is listening for what it types.
|
|
822
|
+
replayKeys(document, keys);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
// Nothing on the page shows one of them and nothing else: the
|
|
826
|
+
// Studio opens the field in its own column, and the keys pressed
|
|
827
|
+
// meanwhile are dropped, as on a page that is not being typed in.
|
|
828
|
+
reply({
|
|
829
|
+
val: VAL_CANVAS_MESSAGE,
|
|
830
|
+
type: "inlineEditUnavailable",
|
|
831
|
+
requestId: message.requestId
|
|
832
|
+
});
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
618
835
|
if (message.type === "theme") {
|
|
619
836
|
setSelectionColors({
|
|
620
837
|
selection: message.selection,
|
|
@@ -703,10 +920,17 @@ function ValCanvasBridge(_ref) {
|
|
|
703
920
|
};
|
|
704
921
|
}, [codeChanged, post]);
|
|
705
922
|
|
|
706
|
-
//
|
|
923
|
+
// The page's log, if the provider's module did not start it already.
|
|
924
|
+
React.useEffect(function () {
|
|
925
|
+
pageLog();
|
|
926
|
+
}, []);
|
|
927
|
+
|
|
928
|
+
// Where the page is, as it moves: a new build is opened there. The log
|
|
929
|
+
// hears of it too, so a client-side navigation starts a new page in it.
|
|
707
930
|
React.useEffect(function () {
|
|
708
931
|
return watchPageLocation(window, function (location) {
|
|
709
|
-
|
|
932
|
+
pageLog().noteLocation();
|
|
933
|
+
post(_objectSpread2({
|
|
710
934
|
val: VAL_CANVAS_MESSAGE,
|
|
711
935
|
type: "location"
|
|
712
936
|
}, location));
|
|
@@ -723,18 +947,85 @@ function ValCanvasBridge(_ref) {
|
|
|
723
947
|
*/
|
|
724
948
|
React.useEffect(function () {
|
|
725
949
|
var onClick = function onClick(event) {
|
|
726
|
-
|
|
950
|
+
var _heldKeys$current2;
|
|
727
951
|
var target = event.target;
|
|
728
952
|
if (!(target instanceof Element)) return;
|
|
953
|
+
// A click in the field being typed in places the caret, and that is
|
|
954
|
+
// all it does: it is neither a pick nor a click on the link or button
|
|
955
|
+
// the text happens to be in. (The caret is the mousedown's, so
|
|
956
|
+
// cancelling the click leaves it where it was put.)
|
|
957
|
+
var editing = inlineEditing.current;
|
|
958
|
+
if (editing !== null && editing.isActive() && editing.contains(target)) {
|
|
959
|
+
event.preventDefault();
|
|
960
|
+
event.stopPropagation();
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
if (!pickingRef.current) return;
|
|
729
964
|
var tagged = target.closest("[data-val-path]");
|
|
730
965
|
var attribute = tagged === null || tagged === void 0 ? void 0 : tagged.getAttribute("data-val-path");
|
|
731
|
-
if (!attribute) return;
|
|
966
|
+
if (!tagged || !attribute) return;
|
|
732
967
|
event.preventDefault();
|
|
733
968
|
event.stopPropagation();
|
|
969
|
+
var paths = Internal$1.splitJoinedSourcePaths(attribute);
|
|
970
|
+
var pick = {
|
|
971
|
+
element: tagged,
|
|
972
|
+
x: event.clientX,
|
|
973
|
+
y: event.clientY
|
|
974
|
+
};
|
|
975
|
+
(_heldKeys$current2 = heldKeys.current) === null || _heldKeys$current2 === void 0 || _heldKeys$current2.release();
|
|
976
|
+
heldKeys.current = null;
|
|
977
|
+
/*
|
|
978
|
+
* Select & edit, and the Studio has said which of this element's
|
|
979
|
+
* fields are texts and what they hold: the edit starts HERE, in the
|
|
980
|
+
* click, rather than a round trip across the frame later. Keys typed
|
|
981
|
+
* straight after the click then go into the text -- in that round
|
|
982
|
+
* trip they went to the page's body, which drops them -- and a phone
|
|
983
|
+
* opens its keyboard, which it does only for a focus given in the tap.
|
|
984
|
+
* Which element shows a field is still decided as `editInline` decides
|
|
985
|
+
* it (`canEditInline`), from the values the Studio sent.
|
|
986
|
+
*/
|
|
987
|
+
var known = textFields.current;
|
|
988
|
+
var offered = known !== null && known.editing ? paths.flatMap(function (path) {
|
|
989
|
+
var _known$editable$get;
|
|
990
|
+
return (_known$editable$get = known.editable.get(path)) !== null && _known$editable$get !== void 0 ? _known$editable$get : [];
|
|
991
|
+
}) : [];
|
|
992
|
+
if (known !== null && offered.length > 0) {
|
|
993
|
+
var _inlineEditing$curren6;
|
|
994
|
+
var reply = function reply(answer) {
|
|
995
|
+
return window.parent.postMessage(answer, known.origin);
|
|
996
|
+
};
|
|
997
|
+
(_inlineEditing$curren6 = inlineEditing.current) === null || _inlineEditing$curren6 === void 0 || _inlineEditing$curren6.release();
|
|
998
|
+
inlineEditing.current = null;
|
|
999
|
+
startedOnClick.current = false;
|
|
1000
|
+
var started = startFirst(offered, pick, {
|
|
1001
|
+
color: selectionColor.current,
|
|
1002
|
+
reply: reply
|
|
1003
|
+
});
|
|
1004
|
+
if (started !== null) {
|
|
1005
|
+
inlineEditing.current = started.editing;
|
|
1006
|
+
startedOnClick.current = true;
|
|
1007
|
+
lastPick.current = null;
|
|
1008
|
+
reply({
|
|
1009
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1010
|
+
type: "inlineEditStarted",
|
|
1011
|
+
requestId: null,
|
|
1012
|
+
path: started.path
|
|
1013
|
+
});
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
/*
|
|
1017
|
+
* A text, but not as the Studio last said: its value changed since
|
|
1018
|
+
* (an edit a moment ago, still on its way). The Studio is asked, as
|
|
1019
|
+
* for any pick, and the keys pressed until it answers are held
|
|
1020
|
+
* rather than lost.
|
|
1021
|
+
*/
|
|
1022
|
+
heldKeys.current = holdKeys(window);
|
|
1023
|
+
}
|
|
1024
|
+
lastPick.current = pick;
|
|
734
1025
|
post({
|
|
735
1026
|
val: VAL_CANVAS_MESSAGE,
|
|
736
1027
|
type: "clicked",
|
|
737
|
-
paths:
|
|
1028
|
+
paths: paths
|
|
738
1029
|
});
|
|
739
1030
|
};
|
|
740
1031
|
document.addEventListener("click", onClick, {
|
|
@@ -747,6 +1038,17 @@ function ValCanvasBridge(_ref) {
|
|
|
747
1038
|
};
|
|
748
1039
|
}, [post]);
|
|
749
1040
|
|
|
1041
|
+
// Select off: an emptied text has its room taken away, and keys held for
|
|
1042
|
+
// an answer to a pick are dropped. Select on: it has its room again.
|
|
1043
|
+
React.useEffect(function () {
|
|
1044
|
+
if (!picking) {
|
|
1045
|
+
var _heldKeys$current3;
|
|
1046
|
+
(_heldKeys$current3 = heldKeys.current) === null || _heldKeys$current3 === void 0 || _heldKeys$current3.release();
|
|
1047
|
+
heldKeys.current = null;
|
|
1048
|
+
}
|
|
1049
|
+
scan();
|
|
1050
|
+
}, [picking, scan]);
|
|
1051
|
+
|
|
750
1052
|
// Esc while picking fields: the key goes to the page, which has the focus
|
|
751
1053
|
// once it has been clicked, so the studio hears of it only from here.
|
|
752
1054
|
React.useEffect(function () {
|
|
@@ -954,7 +1256,11 @@ function ValCanvasBridge(_ref) {
|
|
|
954
1256
|
// CSS string. A path contains quotes (`?p="/"`) and would otherwise
|
|
955
1257
|
// close the selector early.
|
|
956
1258
|
dangerouslySetInnerHTML: {
|
|
957
|
-
__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, "; }") : "",
|
|
1259
|
+
__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, "; }") : "",
|
|
1260
|
+
// The one rule here that moves the page, and only while Select is
|
|
1261
|
+
// on: an emptied text's line of room, without which it cannot be
|
|
1262
|
+
// pointed at. See `emptyTextFields.ts` for why, and how narrowly.
|
|
1263
|
+
picking ? EMPTY_TEXT_RULES : "", highlighted ? highlightRule(highlighted, selectionColors.selection) : ""].filter(Boolean).join("\n")
|
|
958
1264
|
}
|
|
959
1265
|
});
|
|
960
1266
|
}
|
|
@@ -1051,28 +1357,118 @@ function isScrollable(el) {
|
|
|
1051
1357
|
};
|
|
1052
1358
|
return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
|
|
1053
1359
|
}
|
|
1360
|
+
var NO_PATHS = new Set();
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Start editing the first of `candidates` an element on the page shows and
|
|
1364
|
+
* nothing else: the picked element when it carries the candidate's path,
|
|
1365
|
+
* else the first element that does. `null` when none can be.
|
|
1366
|
+
*
|
|
1367
|
+
* What `editInline` does, and what a click does by itself when the Studio has
|
|
1368
|
+
* said ahead of it what the element's texts hold (`textFields`): one way to
|
|
1369
|
+
* start, whichever asked.
|
|
1370
|
+
*/
|
|
1371
|
+
function startFirst(candidates, pick, options) {
|
|
1372
|
+
var reply = options.reply;
|
|
1373
|
+
var _iterator = _createForOfIteratorHelper(candidates),
|
|
1374
|
+
_step;
|
|
1375
|
+
try {
|
|
1376
|
+
var _loop = function _loop() {
|
|
1377
|
+
var candidate = _step.value;
|
|
1378
|
+
var picked = pick !== null && pick.element.isConnected && pathOn(pick.element, candidate.path) !== null ? pick.element : null;
|
|
1379
|
+
var element = picked !== null && picked !== void 0 ? picked : findByPath(candidate.path);
|
|
1380
|
+
if (element === null) return 0; // continue
|
|
1381
|
+
var path = pathOn(element, candidate.path);
|
|
1382
|
+
if (path === null) return 0; // continue
|
|
1383
|
+
var editing = startInlineEditing(element, candidate, {
|
|
1384
|
+
// Where the click was, when it was on this element.
|
|
1385
|
+
at: picked !== null && pick !== null ? {
|
|
1386
|
+
x: pick.x,
|
|
1387
|
+
y: pick.y
|
|
1388
|
+
} : null,
|
|
1389
|
+
color: options.color,
|
|
1390
|
+
onChange: function onChange(value) {
|
|
1391
|
+
return reply({
|
|
1392
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1393
|
+
type: "inlineEdit",
|
|
1394
|
+
path: path,
|
|
1395
|
+
value: value
|
|
1396
|
+
});
|
|
1397
|
+
},
|
|
1398
|
+
onEnd: function onEnd() {
|
|
1399
|
+
return reply({
|
|
1400
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1401
|
+
type: "inlineEditEnded",
|
|
1402
|
+
path: path
|
|
1403
|
+
});
|
|
1404
|
+
},
|
|
1405
|
+
onSelection: function onSelection(selection, rect, caret) {
|
|
1406
|
+
return reply({
|
|
1407
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1408
|
+
type: "inlineEditSelection",
|
|
1409
|
+
path: path,
|
|
1410
|
+
selection: selection,
|
|
1411
|
+
rect: rect,
|
|
1412
|
+
caret: caret
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
if (editing !== null) return {
|
|
1417
|
+
v: {
|
|
1418
|
+
editing: editing,
|
|
1419
|
+
path: path
|
|
1420
|
+
}
|
|
1421
|
+
};
|
|
1422
|
+
},
|
|
1423
|
+
_ret;
|
|
1424
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1425
|
+
_ret = _loop();
|
|
1426
|
+
if (_ret === 0) continue;
|
|
1427
|
+
if (_ret) return _ret.v;
|
|
1428
|
+
}
|
|
1429
|
+
} catch (err) {
|
|
1430
|
+
_iterator.e(err);
|
|
1431
|
+
} finally {
|
|
1432
|
+
_iterator.f();
|
|
1433
|
+
}
|
|
1434
|
+
return null;
|
|
1435
|
+
}
|
|
1054
1436
|
function findByPath(path) {
|
|
1055
1437
|
var elements = document.querySelectorAll("[data-val-path]");
|
|
1056
1438
|
for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
|
|
1057
1439
|
var el = _Array$from[_i];
|
|
1058
|
-
|
|
1059
|
-
if (!attribute) continue;
|
|
1060
|
-
// Compared as strings: the split returns branded `SourcePath`s and what
|
|
1061
|
-
// came back over `postMessage` is a plain string, which is the same value.
|
|
1062
|
-
if (Internal$1.splitJoinedSourcePaths(attribute).some(function (candidate) {
|
|
1063
|
-
return candidate === path;
|
|
1064
|
-
})) {
|
|
1065
|
-
return el;
|
|
1066
|
-
}
|
|
1440
|
+
if (pathOn(el, path) !== null) return el;
|
|
1067
1441
|
}
|
|
1068
1442
|
return null;
|
|
1069
1443
|
}
|
|
1070
1444
|
|
|
1445
|
+
/**
|
|
1446
|
+
* `path` as `element` carries it, or null when it does not.
|
|
1447
|
+
*
|
|
1448
|
+
* Compared as strings: the split returns branded `SourcePath`s and what came
|
|
1449
|
+
* back over `postMessage` is a plain string, which is the same value. What is
|
|
1450
|
+
* returned is the element's own, so it is a `SourcePath` without anyone
|
|
1451
|
+
* having to say so.
|
|
1452
|
+
*/
|
|
1453
|
+
function pathOn(element, path) {
|
|
1454
|
+
var _Internal$splitJoined;
|
|
1455
|
+
var attribute = element.getAttribute("data-val-path");
|
|
1456
|
+
if (!attribute) return null;
|
|
1457
|
+
return (_Internal$splitJoined = Internal$1.splitJoinedSourcePaths(attribute).find(function (candidate) {
|
|
1458
|
+
return candidate === path;
|
|
1459
|
+
})) !== null && _Internal$splitJoined !== void 0 ? _Internal$splitJoined : null;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1071
1462
|
/** What `screenshotPage` answers: the picture, or why it could not be taken. */
|
|
1072
1463
|
function screenshotReply(_x) {
|
|
1073
1464
|
return _screenshotReply.apply(this, arguments);
|
|
1074
1465
|
}
|
|
1075
|
-
/**
|
|
1466
|
+
/**
|
|
1467
|
+
* The page's log (`pageLog.ts`). Started when the provider's module was
|
|
1468
|
+
* evaluated in the canvas, before hydration; started here, as late as the
|
|
1469
|
+
* bridge mounts, only if that did not happen -- a document that was not the
|
|
1470
|
+
* canvas when the provider loaded (see `isValCanvasFrame`).
|
|
1471
|
+
*/
|
|
1076
1472
|
function _screenshotReply() {
|
|
1077
1473
|
_screenshotReply = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(message) {
|
|
1078
1474
|
var _t2, _t3, _t4, _t5;
|
|
@@ -1114,17 +1510,49 @@ function _screenshotReply() {
|
|
|
1114
1510
|
}));
|
|
1115
1511
|
return _screenshotReply.apply(this, arguments);
|
|
1116
1512
|
}
|
|
1513
|
+
function pageLog() {
|
|
1514
|
+
return installPageLog(window);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
/** What `readPageLog` answers: the page's log, or why it could not be read. */
|
|
1518
|
+
function readPageLogReply(message) {
|
|
1519
|
+
try {
|
|
1520
|
+
return {
|
|
1521
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1522
|
+
type: "pageLogRead",
|
|
1523
|
+
requestId: message.requestId,
|
|
1524
|
+
log: pageLog().read(_objectSpread2(_objectSpread2({}, message.sinceNavigation !== undefined ? {
|
|
1525
|
+
sinceNavigation: message.sinceNavigation
|
|
1526
|
+
} : {}), message.levels !== undefined ? {
|
|
1527
|
+
levels: message.levels
|
|
1528
|
+
} : {}))
|
|
1529
|
+
};
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
return {
|
|
1532
|
+
val: VAL_CANVAS_MESSAGE,
|
|
1533
|
+
type: "pageLogRead",
|
|
1534
|
+
requestId: message.requestId,
|
|
1535
|
+
log: null,
|
|
1536
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
/** What `readPage` answers: the page read, or why it could not be. */
|
|
1117
1542
|
function readPageReply(message) {
|
|
1118
1543
|
try {
|
|
1119
1544
|
return {
|
|
1120
1545
|
val: VAL_CANVAS_MESSAGE,
|
|
1121
1546
|
type: "pageRead",
|
|
1122
1547
|
requestId: message.requestId,
|
|
1123
|
-
snapshot: readPageSnapshot(document, _objectSpread2(_objectSpread2({}, message.selector !== undefined ? {
|
|
1548
|
+
snapshot: _objectSpread2(_objectSpread2({}, readPageSnapshot(document, _objectSpread2(_objectSpread2({}, message.selector !== undefined ? {
|
|
1124
1549
|
selector: message.selector
|
|
1125
1550
|
} : {}), message.maxItems !== undefined ? {
|
|
1126
1551
|
maxItems: message.maxItems
|
|
1127
|
-
} : {}))
|
|
1552
|
+
} : {}))), {}, {
|
|
1553
|
+
// So the assistant notices the page threw without asking.
|
|
1554
|
+
log: pageLog().counts()
|
|
1555
|
+
})
|
|
1128
1556
|
};
|
|
1129
1557
|
} catch (error) {
|
|
1130
1558
|
return {
|
|
@@ -1293,6 +1721,19 @@ function PlatformAnalytics(_ref) {
|
|
|
1293
1721
|
});
|
|
1294
1722
|
}
|
|
1295
1723
|
|
|
1724
|
+
installPageLogInCanvasFrame(function () {
|
|
1725
|
+
return hasValEnableCookie(document.cookie);
|
|
1726
|
+
});
|
|
1727
|
+
|
|
1728
|
+
/**
|
|
1729
|
+
* Shows the Overlay menu and updates the store which the client side useVal hook uses to display data.
|
|
1730
|
+
*/
|
|
1731
|
+
/**
|
|
1732
|
+
* How often `/draft/stat` is asked when nothing is in progress.
|
|
1733
|
+
*
|
|
1734
|
+
* Draft mode changes when someone toggles it, which the handshake below already
|
|
1735
|
+
* covers — so this is only there to notice it being changed somewhere else.
|
|
1736
|
+
*/
|
|
1296
1737
|
var DRAFT_IDLE_POLL_MS = 20000;
|
|
1297
1738
|
|
|
1298
1739
|
/**
|