@measured/puck-plugin-heading-analyzer 0.14.2-canary.e529e85 → 0.14.2-canary.e585f20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/dist/index.js +67 -40
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -35956,20 +35956,22 @@ function offsetPoint(x, y, win) {
35956
35956
  let offsetY = 0;
35957
35957
  if (win.parent !== win.self) {
35958
35958
  const iframe = win.frameElement;
35959
- const rect = iframe.getBoundingClientRect();
35960
- const transform = getTransform(iframe);
35961
- offsetX = rect.left;
35962
- offsetY = rect.top;
35963
- if (transform) {
35964
- const {
35965
- x: transformedX,
35966
- y: transformedY
35967
- } = applyTransformPoint(x, y, transform.matrix, transform.origin);
35968
- const point2 = {
35969
- x: transformedX + offsetX,
35970
- y: transformedY + offsetY
35971
- };
35972
- return point2;
35959
+ if (iframe) {
35960
+ const rect = iframe.getBoundingClientRect();
35961
+ const transform = getTransform(iframe);
35962
+ offsetX = rect.left;
35963
+ offsetY = rect.top;
35964
+ if (transform) {
35965
+ const {
35966
+ x: transformedX,
35967
+ y: transformedY
35968
+ } = applyTransformPoint(x, y, transform.matrix, transform.origin);
35969
+ const point2 = {
35970
+ x: transformedX + offsetX,
35971
+ y: transformedY + offsetY
35972
+ };
35973
+ return point2;
35974
+ }
35973
35975
  }
35974
35976
  }
35975
35977
  const point = {
@@ -41050,7 +41052,7 @@ var init_dnd_esm = __esm({
41050
41052
  }
41051
41053
  if (!el.parentElement) {
41052
41054
  const refWindow = el.ownerDocument.defaultView;
41053
- if (refWindow && refWindow.self !== refWindow.parent) {
41055
+ if (refWindow && refWindow.self !== refWindow.parent && refWindow.frameElement) {
41054
41056
  const iframe = refWindow.frameElement;
41055
41057
  return findNearestTransform(iframe);
41056
41058
  }
@@ -41172,7 +41174,7 @@ var init_dnd_esm = __esm({
41172
41174
  }) => {
41173
41175
  const el = querySelectorAllIframe(`[data-rfd-draggable-id="${state.critical.draggable.id}"]`)[0];
41174
41176
  const win = (el == null ? void 0 : el.ownerDocument.defaultView) || window;
41175
- const isInIframe = win !== window;
41177
+ const isInIframe = win !== window && win.frameElement;
41176
41178
  if (isInIframe) {
41177
41179
  const iframe = win.frameElement;
41178
41180
  const viewportBox = getBox(iframe);
@@ -45927,25 +45929,16 @@ var require_dist = __commonJS({
45927
45929
  onStylesLoaded = () => null
45928
45930
  }) => {
45929
45931
  const { document: doc, window: win } = (0, import_react_frame_component.useFrame)();
45930
- (0, import_react22.useLayoutEffect)(() => {
45932
+ (0, import_react22.useEffect)(() => {
45931
45933
  if (!win || !doc) {
45932
45934
  return () => {
45933
45935
  };
45934
45936
  }
45935
- const elements = [];
45937
+ let elements = [];
45938
+ const hashes = {};
45936
45939
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
45937
- const addEl = (el, onLoad = () => {
45940
+ const mirrorEl = (el, onLoad = () => {
45938
45941
  }) => __async2(void 0, null, function* () {
45939
- const index = lookupEl(el);
45940
- if (index > -1) {
45941
- if (debug)
45942
- console.log(
45943
- `Tried to add an element that was already mirrored. Updating instead...`
45944
- );
45945
- elements[index].mirror.innerText = el.innerText;
45946
- onLoad();
45947
- return;
45948
- }
45949
45942
  let mirror;
45950
45943
  if (el.nodeName === "LINK") {
45951
45944
  mirror = document.createElement("style");
@@ -45962,7 +45955,6 @@ var require_dist = __commonJS({
45962
45955
  `Tried to load styles for link element, but couldn't find them. Skipping...`
45963
45956
  );
45964
45957
  }
45965
- onLoad();
45966
45958
  return;
45967
45959
  }
45968
45960
  mirror.innerHTML = styles;
@@ -45970,11 +45962,28 @@ var require_dist = __commonJS({
45970
45962
  } else {
45971
45963
  mirror = el.cloneNode(true);
45972
45964
  }
45965
+ mirror.onload = onLoad;
45966
+ return mirror;
45967
+ });
45968
+ const addEl = (el, onLoad = () => {
45969
+ }) => __async2(void 0, null, function* () {
45970
+ const index = lookupEl(el);
45971
+ if (index > -1) {
45972
+ if (debug)
45973
+ console.log(
45974
+ `Tried to add an element that was already mirrored. Updating instead...`
45975
+ );
45976
+ elements[index].mirror.innerText = el.innerText;
45977
+ onLoad();
45978
+ return;
45979
+ }
45980
+ const mirror = yield mirrorEl(el, onLoad);
45981
+ if (!mirror) {
45982
+ onLoad();
45983
+ return;
45984
+ }
45973
45985
  const elHash = (0, import_object_hash.default)(mirror.outerHTML);
45974
- const existingHashes = collectStyles(doc).map(
45975
- (existingStyle) => existingStyle !== mirror && (0, import_object_hash.default)(existingStyle.outerHTML)
45976
- ).filter(Boolean);
45977
- if (existingHashes.indexOf(elHash) > -1) {
45986
+ if (hashes[elHash]) {
45978
45987
  if (debug)
45979
45988
  console.log(
45980
45989
  `iframe already contains element that is being mirrored. Skipping...`
@@ -45982,6 +45991,7 @@ var require_dist = __commonJS({
45982
45991
  onLoad();
45983
45992
  return;
45984
45993
  }
45994
+ hashes[elHash] = true;
45985
45995
  mirror.onload = onLoad;
45986
45996
  doc.head.append(mirror);
45987
45997
  elements.push({ original: el, mirror });
@@ -45989,6 +45999,7 @@ var require_dist = __commonJS({
45989
45999
  console.log(`Added style node ${el.outerHTML}`);
45990
46000
  });
45991
46001
  const removeEl = (el) => {
46002
+ var _a3, _b;
45992
46003
  const index = lookupEl(el);
45993
46004
  if (index === -1) {
45994
46005
  if (debug)
@@ -45997,7 +46008,9 @@ var require_dist = __commonJS({
45997
46008
  );
45998
46009
  return;
45999
46010
  }
46000
- elements[index].mirror.remove();
46011
+ const elHash = (0, import_object_hash.default)(el.outerHTML);
46012
+ (_b = (_a3 = elements[index]) == null ? void 0 : _a3.mirror) == null ? void 0 : _b.remove();
46013
+ delete hashes[elHash];
46001
46014
  if (debug)
46002
46015
  console.log(`Removed style node ${el.outerHTML}`);
46003
46016
  };
@@ -46026,17 +46039,31 @@ var require_dist = __commonJS({
46026
46039
  const parentDocument = win.parent.document;
46027
46040
  const collectedStyles = collectStyles(parentDocument);
46028
46041
  let mountedCounter = 0;
46029
- collectedStyles.forEach((styleNode) => {
46030
- defer(
46031
- () => addEl(styleNode, () => {
46042
+ Promise.all(
46043
+ collectedStyles.map((styleNode) => __async2(void 0, null, function* () {
46044
+ const mirror = yield mirrorEl(styleNode, () => {
46032
46045
  mountedCounter += 1;
46033
46046
  if (mountedCounter === collectedStyles.length) {
46034
46047
  onStylesLoaded();
46035
46048
  }
46036
- })
46049
+ });
46050
+ if (!mirror)
46051
+ return;
46052
+ elements.push({ original: styleNode, mirror });
46053
+ return mirror;
46054
+ }))
46055
+ ).then((mirrorStyles) => {
46056
+ const filtered = mirrorStyles.filter(
46057
+ (el) => typeof el !== "undefined"
46037
46058
  );
46059
+ doc.head.innerHTML = "";
46060
+ doc.head.append(...filtered);
46061
+ observer.observe(parentDocument.head, { childList: true, subtree: true });
46062
+ filtered.forEach((el) => {
46063
+ const elHash = (0, import_object_hash.default)(el.outerHTML);
46064
+ hashes[elHash] = true;
46065
+ });
46038
46066
  });
46039
- observer.observe(parentDocument.head, { childList: true, subtree: true });
46040
46067
  return () => {
46041
46068
  observer.disconnect();
46042
46069
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck-plugin-heading-analyzer",
3
- "version": "0.14.2-canary.e529e85",
3
+ "version": "0.14.2-canary.e585f20",
4
4
  "author": "Measured Corporation Ltd <hello@measured.co>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",
@@ -18,7 +18,7 @@
18
18
  "dist"
19
19
  ],
20
20
  "devDependencies": {
21
- "@measured/puck": "^0.14.2-canary.e529e85",
21
+ "@measured/puck": "^0.14.2-canary.e585f20",
22
22
  "@types/react": "^18.2.0",
23
23
  "@types/react-dom": "^18.2.0",
24
24
  "eslint": "^7.32.0",