@measured/puck-plugin-heading-analyzer 0.14.2-canary.ba01fb0 → 0.14.2-canary.c60c5a9

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.
Files changed (2) hide show
  1. package/dist/index.js +69 -31
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -45907,7 +45907,10 @@ var require_dist = __commonJS({
45907
45907
  return collected;
45908
45908
  };
45909
45909
  var getStyleSheet = (el) => {
45910
- return Array.from(document.styleSheets).find((ss) => ss.ownerNode === el);
45910
+ return Array.from(document.styleSheets).find((ss) => {
45911
+ const ownerNode = ss.ownerNode;
45912
+ return ownerNode.href === el.href;
45913
+ });
45911
45914
  };
45912
45915
  var getStyles2 = (styleSheet) => {
45913
45916
  if (styleSheet) {
@@ -45929,32 +45932,29 @@ var require_dist = __commonJS({
45929
45932
  onStylesLoaded = () => null
45930
45933
  }) => {
45931
45934
  const { document: doc, window: win } = (0, import_react_frame_component.useFrame)();
45932
- (0, import_react22.useLayoutEffect)(() => {
45935
+ (0, import_react22.useEffect)(() => {
45933
45936
  if (!win || !doc) {
45934
45937
  return () => {
45935
45938
  };
45936
45939
  }
45937
- const elements = [];
45940
+ let elements = [];
45941
+ const hashes = {};
45938
45942
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
45939
- const addEl = (el, onLoad = () => {
45943
+ const mirrorEl = (el, onLoad = () => {
45940
45944
  }) => __async2(void 0, null, function* () {
45941
- const index = lookupEl(el);
45942
- if (index > -1) {
45943
- if (debug)
45944
- console.log(
45945
- `Tried to add an element that was already mirrored. Updating instead...`
45946
- );
45947
- elements[index].mirror.innerText = el.innerText;
45948
- onLoad();
45949
- return;
45950
- }
45951
45945
  let mirror;
45952
45946
  if (el.nodeName === "LINK") {
45953
45947
  mirror = document.createElement("style");
45954
45948
  mirror.type = "text/css";
45955
45949
  let styleSheet = getStyleSheet(el);
45956
45950
  if (!styleSheet) {
45957
- yield new Promise((resolve) => el.onload = resolve);
45951
+ yield new Promise((resolve) => {
45952
+ const fn = () => {
45953
+ resolve();
45954
+ el.removeEventListener("load", fn);
45955
+ };
45956
+ el.addEventListener("load", fn);
45957
+ });
45958
45958
  styleSheet = getStyleSheet(el);
45959
45959
  }
45960
45960
  const styles = getStyles2(styleSheet);
@@ -45964,7 +45964,6 @@ var require_dist = __commonJS({
45964
45964
  `Tried to load styles for link element, but couldn't find them. Skipping...`
45965
45965
  );
45966
45966
  }
45967
- onLoad();
45968
45967
  return;
45969
45968
  }
45970
45969
  mirror.innerHTML = styles;
@@ -45972,11 +45971,28 @@ var require_dist = __commonJS({
45972
45971
  } else {
45973
45972
  mirror = el.cloneNode(true);
45974
45973
  }
45974
+ mirror.onload = onLoad;
45975
+ return mirror;
45976
+ });
45977
+ const addEl = (el, onLoad = () => {
45978
+ }) => __async2(void 0, null, function* () {
45979
+ const index = lookupEl(el);
45980
+ if (index > -1) {
45981
+ if (debug)
45982
+ console.log(
45983
+ `Tried to add an element that was already mirrored. Updating instead...`
45984
+ );
45985
+ elements[index].mirror.innerText = el.innerText;
45986
+ onLoad();
45987
+ return;
45988
+ }
45989
+ const mirror = yield mirrorEl(el, onLoad);
45990
+ if (!mirror) {
45991
+ onLoad();
45992
+ return;
45993
+ }
45975
45994
  const elHash = (0, import_object_hash.default)(mirror.outerHTML);
45976
- const existingHashes = collectStyles(doc).map(
45977
- (existingStyle) => existingStyle !== mirror && (0, import_object_hash.default)(existingStyle.outerHTML)
45978
- ).filter(Boolean);
45979
- if (existingHashes.indexOf(elHash) > -1) {
45995
+ if (hashes[elHash]) {
45980
45996
  if (debug)
45981
45997
  console.log(
45982
45998
  `iframe already contains element that is being mirrored. Skipping...`
@@ -45984,6 +46000,7 @@ var require_dist = __commonJS({
45984
46000
  onLoad();
45985
46001
  return;
45986
46002
  }
46003
+ hashes[elHash] = true;
45987
46004
  mirror.onload = onLoad;
45988
46005
  doc.head.append(mirror);
45989
46006
  elements.push({ original: el, mirror });
@@ -45991,6 +46008,7 @@ var require_dist = __commonJS({
45991
46008
  console.log(`Added style node ${el.outerHTML}`);
45992
46009
  });
45993
46010
  const removeEl = (el) => {
46011
+ var _a3, _b;
45994
46012
  const index = lookupEl(el);
45995
46013
  if (index === -1) {
45996
46014
  if (debug)
@@ -45999,7 +46017,9 @@ var require_dist = __commonJS({
45999
46017
  );
46000
46018
  return;
46001
46019
  }
46002
- elements[index].mirror.remove();
46020
+ const elHash = (0, import_object_hash.default)(el.outerHTML);
46021
+ (_b = (_a3 = elements[index]) == null ? void 0 : _a3.mirror) == null ? void 0 : _b.remove();
46022
+ delete hashes[elHash];
46003
46023
  if (debug)
46004
46024
  console.log(`Removed style node ${el.outerHTML}`);
46005
46025
  };
@@ -46027,18 +46047,35 @@ var require_dist = __commonJS({
46027
46047
  });
46028
46048
  const parentDocument = win.parent.document;
46029
46049
  const collectedStyles = collectStyles(parentDocument);
46030
- let mountedCounter = 0;
46031
- collectedStyles.forEach((styleNode) => {
46032
- defer(
46033
- () => addEl(styleNode, () => {
46034
- mountedCounter += 1;
46035
- if (mountedCounter === collectedStyles.length) {
46036
- onStylesLoaded();
46050
+ const hrefs = [];
46051
+ Promise.all(
46052
+ collectedStyles.map((styleNode, i2) => __async2(void 0, null, function* () {
46053
+ if (styleNode.nodeName === "LINK") {
46054
+ const linkHref = styleNode.href;
46055
+ if (hrefs.indexOf(linkHref) > -1) {
46056
+ return;
46037
46057
  }
46038
- })
46058
+ hrefs.push(linkHref);
46059
+ }
46060
+ const mirror = yield mirrorEl(styleNode);
46061
+ if (!mirror)
46062
+ return;
46063
+ elements.push({ original: styleNode, mirror });
46064
+ return mirror;
46065
+ }))
46066
+ ).then((mirrorStyles) => {
46067
+ const filtered = mirrorStyles.filter(
46068
+ (el) => typeof el !== "undefined"
46039
46069
  );
46070
+ doc.head.innerHTML = "";
46071
+ doc.head.append(...filtered);
46072
+ observer.observe(parentDocument.head, { childList: true, subtree: true });
46073
+ filtered.forEach((el) => {
46074
+ const elHash = (0, import_object_hash.default)(el.outerHTML);
46075
+ hashes[elHash] = true;
46076
+ });
46077
+ onStylesLoaded();
46040
46078
  });
46041
- observer.observe(parentDocument.head, { childList: true, subtree: true });
46042
46079
  return () => {
46043
46080
  observer.disconnect();
46044
46081
  };
@@ -78325,7 +78362,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
78325
78362
  onChange(e2.currentTarget.value);
78326
78363
  },
78327
78364
  disabled: readOnly,
78328
- defaultChecked: value === option.value
78365
+ checked: value === option.value
78329
78366
  }
78330
78367
  ),
78331
78368
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName14("radioInner"), children: option.label || option.value })
@@ -79820,6 +79857,7 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
79820
79857
  children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
79821
79858
  DragDropContext2,
79822
79859
  {
79860
+ autoScrollerOptions: { disabled: iframe.disableAutoScroll },
79823
79861
  onDragUpdate: (update2) => {
79824
79862
  setDraggedItem(__spreadValues2(__spreadValues2({}, draggedItem), update2));
79825
79863
  onDragStartOrUpdate(update2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck-plugin-heading-analyzer",
3
- "version": "0.14.2-canary.ba01fb0",
3
+ "version": "0.14.2-canary.c60c5a9",
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.ba01fb0",
21
+ "@measured/puck": "^0.14.2-canary.c60c5a9",
22
22
  "@types/react": "^18.2.0",
23
23
  "@types/react-dom": "^18.2.0",
24
24
  "eslint": "^7.32.0",