@valbuild/next 0.108.3 → 0.108.5

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.
@@ -289,10 +289,8 @@ function ValCanvasBridge(_ref) {
289
289
  setHighlighted(message.path);
290
290
  if (message.path !== null && message.scrollIntoView) {
291
291
  var target = findByPath(message.path);
292
- target === null || target === void 0 || target.scrollIntoView({
293
- block: "center",
294
- behavior: "smooth"
295
- });
292
+ // NOT `scrollIntoView` — see `scrollWithinPage`.
293
+ if (target !== null) scrollWithinPage(target);
296
294
  }
297
295
  };
298
296
  window.addEventListener("message", listener);
@@ -499,6 +497,77 @@ function highlightRule(path) {
499
497
  var selectors = ["[data-val-path=".concat(value, "]"), "[data-val-path^=".concat(first, "]"), "[data-val-path$=".concat(last, "]"), "[data-val-path*=".concat(inner, "]")].join(",\n");
500
498
  return "".concat(selectors, " { outline: 2px solid ").concat(SELECTION, "; outline-offset: 1px; }");
501
499
  }
500
+
501
+ /**
502
+ * Bring an element into view WITHOUT scrolling anything outside this page.
503
+ *
504
+ * `Element.scrollIntoView` would be the obvious thing, and it is the thing that
505
+ * broke the studio. It scrolls every scroll container between the element and
506
+ * the viewport, and for a same-origin frame that chain does not stop at the
507
+ * frame: it continues into the embedder and scrolls the studio's own containers
508
+ * too. Measured in Chromium — with the studio's phone panes placed on the
509
+ * editor, a single `scrollIntoView` in here pulls them back onto the canvas, and
510
+ * because it reveals the element rather than the frame it can leave them
511
+ * anywhere in between, showing half of each.
512
+ *
513
+ * That is not a thing the page has any business doing. It was asked to show one
514
+ * of its own elements; where the studio is looking is the studio's affair. So
515
+ * the scrolling is done by hand, one scrollport at a time, and the walk stops at
516
+ * this document.
517
+ *
518
+ * Only the document centres the target vertically — it is being pointed out,
519
+ * and something flush against the top edge of the fold does not read as pointed
520
+ * out. Every scrollport inside the page is moved as little as it takes to bring
521
+ * the target inside it: a carousel, a sticky sidebar or a sideways-scrolling
522
+ * table is showing what it is showing on purpose, and re-centring one that did
523
+ * not need moving is the page rearranging itself around a highlight.
524
+ */
525
+ function scrollWithinPage(target) {
526
+ var node = target.parentElement;
527
+ while (node !== null) {
528
+ var isRoot = node === document.body || node === document.documentElement;
529
+ if (isRoot) break;
530
+ if (isScrollable(node)) {
531
+ var port = node.getBoundingClientRect();
532
+ var _box = target.getBoundingClientRect();
533
+ node.scrollTop += delta(_box.top - port.top, _box.height, node.clientHeight, false);
534
+ node.scrollLeft += delta(_box.left - port.left, _box.width, node.clientWidth, false);
535
+ }
536
+ node = node.parentElement;
537
+ }
538
+ // And this document, which is the last scrollport there is as far as the page
539
+ // is concerned. `window`, not `documentElement.scrollIntoView`-by-another-name:
540
+ // this cannot reach past the frame.
541
+ var box = target.getBoundingClientRect();
542
+ window.scrollTo({
543
+ top: Math.max(0, window.scrollY + delta(box.top, box.height, window.innerHeight, true)),
544
+ left: Math.max(0, window.scrollX + delta(box.left, box.width, window.innerWidth, false)),
545
+ behavior: "smooth"
546
+ });
547
+ }
548
+
549
+ /**
550
+ * How far a scrollport has to move for `size` at `offset` to be shown.
551
+ *
552
+ * `center` asks for the middle of the port; without it the answer is zero
553
+ * whenever the thing is already inside, which is what keeps a scrollport that
554
+ * did not need moving from being disturbed.
555
+ */
556
+ function delta(offset, size, port, center) {
557
+ if (center) return offset - (port - size) / 2;
558
+ if (offset < 0) return offset;
559
+ if (offset + size > port) return Math.min(offset, offset + size - port);
560
+ return 0;
561
+ }
562
+
563
+ /** Whether this element scrolls its own content, rather than growing with it. */
564
+ function isScrollable(el) {
565
+ var style = getComputedStyle(el);
566
+ var scrolls = function scrolls(value) {
567
+ return value === "auto" || value === "scroll" || value === "overlay";
568
+ };
569
+ return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
570
+ }
502
571
  function findByPath(path) {
503
572
  var elements = document.querySelectorAll("[data-val-path]");
504
573
  for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
@@ -281,10 +281,8 @@ function ValCanvasBridge(_ref) {
281
281
  setHighlighted(message.path);
282
282
  if (message.path !== null && message.scrollIntoView) {
283
283
  var target = findByPath(message.path);
284
- target === null || target === void 0 || target.scrollIntoView({
285
- block: "center",
286
- behavior: "smooth"
287
- });
284
+ // NOT `scrollIntoView` — see `scrollWithinPage`.
285
+ if (target !== null) scrollWithinPage(target);
288
286
  }
289
287
  };
290
288
  window.addEventListener("message", listener);
@@ -491,6 +489,77 @@ function highlightRule(path) {
491
489
  var selectors = ["[data-val-path=".concat(value, "]"), "[data-val-path^=".concat(first, "]"), "[data-val-path$=".concat(last, "]"), "[data-val-path*=".concat(inner, "]")].join(",\n");
492
490
  return "".concat(selectors, " { outline: 2px solid ").concat(SELECTION, "; outline-offset: 1px; }");
493
491
  }
492
+
493
+ /**
494
+ * Bring an element into view WITHOUT scrolling anything outside this page.
495
+ *
496
+ * `Element.scrollIntoView` would be the obvious thing, and it is the thing that
497
+ * broke the studio. It scrolls every scroll container between the element and
498
+ * the viewport, and for a same-origin frame that chain does not stop at the
499
+ * frame: it continues into the embedder and scrolls the studio's own containers
500
+ * too. Measured in Chromium — with the studio's phone panes placed on the
501
+ * editor, a single `scrollIntoView` in here pulls them back onto the canvas, and
502
+ * because it reveals the element rather than the frame it can leave them
503
+ * anywhere in between, showing half of each.
504
+ *
505
+ * That is not a thing the page has any business doing. It was asked to show one
506
+ * of its own elements; where the studio is looking is the studio's affair. So
507
+ * the scrolling is done by hand, one scrollport at a time, and the walk stops at
508
+ * this document.
509
+ *
510
+ * Only the document centres the target vertically — it is being pointed out,
511
+ * and something flush against the top edge of the fold does not read as pointed
512
+ * out. Every scrollport inside the page is moved as little as it takes to bring
513
+ * the target inside it: a carousel, a sticky sidebar or a sideways-scrolling
514
+ * table is showing what it is showing on purpose, and re-centring one that did
515
+ * not need moving is the page rearranging itself around a highlight.
516
+ */
517
+ function scrollWithinPage(target) {
518
+ var node = target.parentElement;
519
+ while (node !== null) {
520
+ var isRoot = node === document.body || node === document.documentElement;
521
+ if (isRoot) break;
522
+ if (isScrollable(node)) {
523
+ var port = node.getBoundingClientRect();
524
+ var _box = target.getBoundingClientRect();
525
+ node.scrollTop += delta(_box.top - port.top, _box.height, node.clientHeight, false);
526
+ node.scrollLeft += delta(_box.left - port.left, _box.width, node.clientWidth, false);
527
+ }
528
+ node = node.parentElement;
529
+ }
530
+ // And this document, which is the last scrollport there is as far as the page
531
+ // is concerned. `window`, not `documentElement.scrollIntoView`-by-another-name:
532
+ // this cannot reach past the frame.
533
+ var box = target.getBoundingClientRect();
534
+ window.scrollTo({
535
+ top: Math.max(0, window.scrollY + delta(box.top, box.height, window.innerHeight, true)),
536
+ left: Math.max(0, window.scrollX + delta(box.left, box.width, window.innerWidth, false)),
537
+ behavior: "smooth"
538
+ });
539
+ }
540
+
541
+ /**
542
+ * How far a scrollport has to move for `size` at `offset` to be shown.
543
+ *
544
+ * `center` asks for the middle of the port; without it the answer is zero
545
+ * whenever the thing is already inside, which is what keeps a scrollport that
546
+ * did not need moving from being disturbed.
547
+ */
548
+ function delta(offset, size, port, center) {
549
+ if (center) return offset - (port - size) / 2;
550
+ if (offset < 0) return offset;
551
+ if (offset + size > port) return Math.min(offset, offset + size - port);
552
+ return 0;
553
+ }
554
+
555
+ /** Whether this element scrolls its own content, rather than growing with it. */
556
+ function isScrollable(el) {
557
+ var style = getComputedStyle(el);
558
+ var scrolls = function scrolls(value) {
559
+ return value === "auto" || value === "scroll" || value === "overlay";
560
+ };
561
+ return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
562
+ }
494
563
  function findByPath(path) {
495
564
  var elements = document.querySelectorAll("[data-val-path]");
496
565
  for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./ValCanvasBridge-e62125f8.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./ValCanvasBridge-e62125f8.cjs.dev.js");
7
+ }
@@ -289,10 +289,8 @@ function ValCanvasBridge(_ref) {
289
289
  setHighlighted(message.path);
290
290
  if (message.path !== null && message.scrollIntoView) {
291
291
  var target = findByPath(message.path);
292
- target === null || target === void 0 || target.scrollIntoView({
293
- block: "center",
294
- behavior: "smooth"
295
- });
292
+ // NOT `scrollIntoView` — see `scrollWithinPage`.
293
+ if (target !== null) scrollWithinPage(target);
296
294
  }
297
295
  };
298
296
  window.addEventListener("message", listener);
@@ -499,6 +497,77 @@ function highlightRule(path) {
499
497
  var selectors = ["[data-val-path=".concat(value, "]"), "[data-val-path^=".concat(first, "]"), "[data-val-path$=".concat(last, "]"), "[data-val-path*=".concat(inner, "]")].join(",\n");
500
498
  return "".concat(selectors, " { outline: 2px solid ").concat(SELECTION, "; outline-offset: 1px; }");
501
499
  }
500
+
501
+ /**
502
+ * Bring an element into view WITHOUT scrolling anything outside this page.
503
+ *
504
+ * `Element.scrollIntoView` would be the obvious thing, and it is the thing that
505
+ * broke the studio. It scrolls every scroll container between the element and
506
+ * the viewport, and for a same-origin frame that chain does not stop at the
507
+ * frame: it continues into the embedder and scrolls the studio's own containers
508
+ * too. Measured in Chromium — with the studio's phone panes placed on the
509
+ * editor, a single `scrollIntoView` in here pulls them back onto the canvas, and
510
+ * because it reveals the element rather than the frame it can leave them
511
+ * anywhere in between, showing half of each.
512
+ *
513
+ * That is not a thing the page has any business doing. It was asked to show one
514
+ * of its own elements; where the studio is looking is the studio's affair. So
515
+ * the scrolling is done by hand, one scrollport at a time, and the walk stops at
516
+ * this document.
517
+ *
518
+ * Only the document centres the target vertically — it is being pointed out,
519
+ * and something flush against the top edge of the fold does not read as pointed
520
+ * out. Every scrollport inside the page is moved as little as it takes to bring
521
+ * the target inside it: a carousel, a sticky sidebar or a sideways-scrolling
522
+ * table is showing what it is showing on purpose, and re-centring one that did
523
+ * not need moving is the page rearranging itself around a highlight.
524
+ */
525
+ function scrollWithinPage(target) {
526
+ var node = target.parentElement;
527
+ while (node !== null) {
528
+ var isRoot = node === document.body || node === document.documentElement;
529
+ if (isRoot) break;
530
+ if (isScrollable(node)) {
531
+ var port = node.getBoundingClientRect();
532
+ var _box = target.getBoundingClientRect();
533
+ node.scrollTop += delta(_box.top - port.top, _box.height, node.clientHeight, false);
534
+ node.scrollLeft += delta(_box.left - port.left, _box.width, node.clientWidth, false);
535
+ }
536
+ node = node.parentElement;
537
+ }
538
+ // And this document, which is the last scrollport there is as far as the page
539
+ // is concerned. `window`, not `documentElement.scrollIntoView`-by-another-name:
540
+ // this cannot reach past the frame.
541
+ var box = target.getBoundingClientRect();
542
+ window.scrollTo({
543
+ top: Math.max(0, window.scrollY + delta(box.top, box.height, window.innerHeight, true)),
544
+ left: Math.max(0, window.scrollX + delta(box.left, box.width, window.innerWidth, false)),
545
+ behavior: "smooth"
546
+ });
547
+ }
548
+
549
+ /**
550
+ * How far a scrollport has to move for `size` at `offset` to be shown.
551
+ *
552
+ * `center` asks for the middle of the port; without it the answer is zero
553
+ * whenever the thing is already inside, which is what keeps a scrollport that
554
+ * did not need moving from being disturbed.
555
+ */
556
+ function delta(offset, size, port, center) {
557
+ if (center) return offset - (port - size) / 2;
558
+ if (offset < 0) return offset;
559
+ if (offset + size > port) return Math.min(offset, offset + size - port);
560
+ return 0;
561
+ }
562
+
563
+ /** Whether this element scrolls its own content, rather than growing with it. */
564
+ function isScrollable(el) {
565
+ var style = getComputedStyle(el);
566
+ var scrolls = function scrolls(value) {
567
+ return value === "auto" || value === "scroll" || value === "overlay";
568
+ };
569
+ return scrolls(style.overflowY) && el.scrollHeight > el.clientHeight || scrolls(style.overflowX) && el.scrollWidth > el.clientWidth;
570
+ }
502
571
  function findByPath(path) {
503
572
  var elements = document.querySelectorAll("[data-val-path]");
504
573
  for (var _i = 0, _Array$from = Array.from(elements); _i < _Array$from.length; _i++) {
@@ -11,7 +11,7 @@ import { SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
11
11
  import { VAL_THEME_SESSION_STORAGE_KEY, createValClient, isValCanvasFrame } from '@valbuild/shared/internal';
12
12
  import { p as prefixStyles, u as useConfigStorageSave, f as floatDarkBg, d as floatLightBg, v as valPrefixedClass, c as cn } from './fallbackColors-5ead2c26.esm.js';
13
13
  import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-5758a730.esm.js';
14
- import { ValCanvasBridge } from './ValCanvasBridge-1310aaeb.esm.js';
14
+ import { ValCanvasBridge } from './ValCanvasBridge-d9948526.esm.js';
15
15
  import { jsxs, jsx } from 'react/jsx-runtime';
16
16
  import './unsupportedIterableToArray-5baabfdc.esm.js';
17
17
  import './defineProperty-cca5affa.esm.js';
@@ -15,7 +15,7 @@ var stega = require('@valbuild/react/stega');
15
15
  var internal = require('@valbuild/shared/internal');
16
16
  var fallbackColors = require('./fallbackColors-d4a5b0da.cjs.prod.js');
17
17
  var createForOfIteratorHelper = require('./createForOfIteratorHelper-d4afcad8.cjs.prod.js');
18
- var ValCanvasBridge = require('./ValCanvasBridge-32299c6e.cjs.prod.js');
18
+ var ValCanvasBridge = require('./ValCanvasBridge-e62125f8.cjs.prod.js');
19
19
  var jsxRuntime = require('react/jsx-runtime');
20
20
  require('./unsupportedIterableToArray-0d2087a2.cjs.prod.js');
21
21
  require('./defineProperty-8951f469.cjs.prod.js');
@@ -15,7 +15,7 @@ var stega = require('@valbuild/react/stega');
15
15
  var internal = require('@valbuild/shared/internal');
16
16
  var fallbackColors = require('./fallbackColors-9a2ac53a.cjs.dev.js');
17
17
  var createForOfIteratorHelper = require('./createForOfIteratorHelper-0445603c.cjs.dev.js');
18
- var ValCanvasBridge = require('./ValCanvasBridge-cb2d9112.cjs.dev.js');
18
+ var ValCanvasBridge = require('./ValCanvasBridge-9d148bdd.cjs.dev.js');
19
19
  var jsxRuntime = require('react/jsx-runtime');
20
20
  require('./unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
21
21
  require('./defineProperty-f90345d7.cjs.dev.js');
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "next",
13
13
  "react"
14
14
  ],
15
- "version": "0.108.3",
15
+ "version": "0.108.5",
16
16
  "main": "dist/valbuild-next.cjs.js",
17
17
  "module": "dist/valbuild-next.esm.js",
18
18
  "exports": {
@@ -47,12 +47,12 @@
47
47
  "dependencies": {
48
48
  "client-only": "^0.0.1",
49
49
  "server-only": "^0.0.1",
50
+ "@valbuild/language-server": "0.108.5",
51
+ "@valbuild/server": "0.108.5",
52
+ "@valbuild/react": "0.108.5",
50
53
  "@valbuild/core": "0.106.0",
51
- "@valbuild/language-server": "0.108.3",
52
- "@valbuild/server": "0.108.3",
53
- "@valbuild/react": "0.108.3",
54
- "@valbuild/shared": "0.108.0",
55
- "@valbuild/ui": "0.108.3"
54
+ "@valbuild/ui": "0.108.5",
55
+ "@valbuild/shared": "0.108.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@testing-library/react": "^16.3.3",
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./ValCanvasBridge-32299c6e.cjs.prod.js");
5
- } else {
6
- module.exports = require("./ValCanvasBridge-32299c6e.cjs.dev.js");
7
- }