Files
Ivan Starkov 5de42b2d02 fix: Ensure outline stays within canvas bounds (#4570)
## Description

Playground


https://p-183a0702-0620-49ac-84b6-066dbce1d300-dot-fix-outline.development.webstudio.is/


<img width="1229" alt="image"
src="https://github.com/user-attachments/assets/5c6a8c73-70e6-48af-8cbd-6c12144d55ee"
/>

todo:
- [x] - fix if horizontal scroll 
<img width="629" alt="image"
src="https://github.com/user-attachments/assets/d904d7ac-f74a-4116-993f-00b8b14c39dd"
/>

- [x] - fix if vertical

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2024-12-12 13:09:51 +03:00

29 lines
794 B
TypeScript

import { shallowEqual } from "shallow-equal";
import { $canvasScrollbarSize } from "~/builder/shared/nano-states";
export const subscribeScrollbarSize = ({ signal }: { signal: AbortSignal }) => {
const getScrollbarSize = () => ({
width: window.innerWidth - document.documentElement.clientWidth,
height: window.innerHeight - document.documentElement.clientHeight,
});
$canvasScrollbarSize.set(getScrollbarSize());
const observer = new ResizeObserver(() => {
const newSize = getScrollbarSize();
if (!shallowEqual($canvasScrollbarSize.get(), newSize)) {
$canvasScrollbarSize.set(newSize);
}
});
observer.observe(document.documentElement);
signal.addEventListener(
"abort",
() => {
observer.disconnect();
},
{ once: true }
);
};