Skip to content

Commit

Permalink
add client rect observer to iframe script
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisShank committed Nov 26, 2024
1 parent d154c79 commit f4e579e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/arrows/iframe-script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FolkGeometry } from '../canvas/fc-geometry';
import { ClientRectObserverManager, ClientRectObserverEntry } from '../client-rect-observer.ts';

const clientRectObserver = new ClientRectObserverManager();

interface ObservedElementEntry {
selector: string;
element: Element;
Expand Down Expand Up @@ -51,7 +53,13 @@ if (window.parent !== window) {
const observedElements = new Map();
const observedSelectors = new Map();

function boundingBoxCallback(entry: ClientRectObserverEntry) {}
function boundingBoxCallback(entry: ClientRectObserverEntry) {
window.parent.postMessage({
type: 'folk-element-change',
selector: observedSelectors.get(entry.target),
boundingBox: entry.contentRect,
});
}

function onGeometryChange(event) {
window.parent.postMessage({
Expand Down Expand Up @@ -82,7 +90,7 @@ if (window.parent !== window) {
boundingBox: element.getClientRect(),
});
} else {
// use BoundingBoxObserver
clientRectObserver.observe(element, boundingBoxCallback);
}
return;
}
Expand All @@ -98,6 +106,7 @@ if (window.parent !== window) {
observedElements.delete(selector);
observedSelectors.delete(element);
} else {
clientRectObserver.unobserve(element, boundingBoxCallback);
}

return;
Expand Down

0 comments on commit f4e579e

Please sign in to comment.