@betterstore/react 0.3.67 → 0.3.69

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.69
4
+
5
+ ### Patch Changes
6
+
7
+ - bug fix
8
+
9
+ ## 0.3.68
10
+
11
+ ### Patch Changes
12
+
13
+ - bug fix
14
+
3
15
  ## 0.3.67
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -521,6 +521,7 @@ var css_248z = "/*! tailwindcss v4.1.8 | MIT License | https://tailwindcss.com *
521
521
  const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
522
522
  const [iframeBody, setIframeBody] = React.useState(null);
523
523
  const styleRef = React.useRef(null);
524
+ React.useRef(null);
524
525
  const resizeObserver = React.useRef();
525
526
  const injectStyles = React.useCallback((doc) => {
526
527
  var _a;
@@ -528,17 +529,30 @@ const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
528
529
  if ((_a = styleRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) {
529
530
  styleRef.current.parentNode.removeChild(styleRef.current);
530
531
  }
531
- // Inject global CSS
532
532
  const styleEl = doc.createElement("style");
533
533
  styleEl.textContent = css_248z;
534
534
  doc.head.appendChild(styleEl);
535
535
  styleRef.current = styleEl;
536
- // Clone Framer Motion styles into iframe
537
- Array.from(document.querySelectorAll("style[data-motion]")).forEach((styleTag) => {
538
- const clone = styleTag.cloneNode(true);
539
- doc.head.appendChild(clone);
540
- });
541
536
  }, []);
537
+ const cloneGlobals = (iframeWin) => {
538
+ const parentWin = window;
539
+ // Grab all own props of the parent window...
540
+ Object.getOwnPropertyNames(parentWin).forEach((key) => {
541
+ // Skip non–configurable or already-present props
542
+ if (key in iframeWin)
543
+ return;
544
+ const desc = Object.getOwnPropertyDescriptor(parentWin, key);
545
+ // Only clone functions or configurable props
546
+ if (typeof desc.value === "function" ||
547
+ (desc.configurable && (desc.writable || desc.get))) {
548
+ Object.defineProperty(iframeWin, key, Object.assign(Object.assign({}, desc), {
549
+ // if it's a function, bind it back to parent window
550
+ value: typeof desc.value === "function"
551
+ ? desc.value.bind(parentWin)
552
+ : desc.value }));
553
+ }
554
+ });
555
+ };
542
556
  const updateHeight = React.useCallback(() => {
543
557
  const iframe = iframeRef.current;
544
558
  const doc = iframe === null || iframe === void 0 ? void 0 : iframe.contentDocument;
@@ -552,10 +566,11 @@ const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
552
566
  if (!iframe)
553
567
  return;
554
568
  const doc = iframe.contentDocument;
569
+ cloneGlobals(iframe.contentWindow);
555
570
  injectStyles(doc);
556
571
  setIframeBody(doc.body);
557
572
  updateHeight();
558
- // Observe body size changes
573
+ // Observe body mutations & size
559
574
  if ("ResizeObserver" in window) {
560
575
  resizeObserver.current = new ResizeObserver(updateHeight);
561
576
  resizeObserver.current.observe(doc.body);
@@ -566,7 +581,9 @@ const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
566
581
  const iframe = iframeRef.current;
567
582
  if (!iframe)
568
583
  return;
584
+ // Attach onLoad
569
585
  iframe.addEventListener("load", handleLoad);
586
+ // If already loaded
570
587
  if (((_a = iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.readyState) === "complete") {
571
588
  handleLoad();
572
589
  }
@@ -579,6 +596,7 @@ const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
579
596
  }
580
597
  };
581
598
  }, [iframeRef, handleLoad]);
599
+ // Update on window resize
582
600
  React.useEffect(() => {
583
601
  window.addEventListener("resize", updateHeight);
584
602
  return () => {
package/dist/index.mjs CHANGED
@@ -498,6 +498,7 @@ var css_248z = "/*! tailwindcss v4.1.8 | MIT License | https://tailwindcss.com *
498
498
  const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef }) => {
499
499
  const [iframeBody, setIframeBody] = useState(null);
500
500
  const styleRef = useRef(null);
501
+ useRef(null);
501
502
  const resizeObserver = useRef();
502
503
  const injectStyles = useCallback((doc) => {
503
504
  var _a;
@@ -505,17 +506,30 @@ const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef })
505
506
  if ((_a = styleRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) {
506
507
  styleRef.current.parentNode.removeChild(styleRef.current);
507
508
  }
508
- // Inject global CSS
509
509
  const styleEl = doc.createElement("style");
510
510
  styleEl.textContent = css_248z;
511
511
  doc.head.appendChild(styleEl);
512
512
  styleRef.current = styleEl;
513
- // Clone Framer Motion styles into iframe
514
- Array.from(document.querySelectorAll("style[data-motion]")).forEach((styleTag) => {
515
- const clone = styleTag.cloneNode(true);
516
- doc.head.appendChild(clone);
517
- });
518
513
  }, []);
514
+ const cloneGlobals = (iframeWin) => {
515
+ const parentWin = window;
516
+ // Grab all own props of the parent window...
517
+ Object.getOwnPropertyNames(parentWin).forEach((key) => {
518
+ // Skip non–configurable or already-present props
519
+ if (key in iframeWin)
520
+ return;
521
+ const desc = Object.getOwnPropertyDescriptor(parentWin, key);
522
+ // Only clone functions or configurable props
523
+ if (typeof desc.value === "function" ||
524
+ (desc.configurable && (desc.writable || desc.get))) {
525
+ Object.defineProperty(iframeWin, key, Object.assign(Object.assign({}, desc), {
526
+ // if it's a function, bind it back to parent window
527
+ value: typeof desc.value === "function"
528
+ ? desc.value.bind(parentWin)
529
+ : desc.value }));
530
+ }
531
+ });
532
+ };
519
533
  const updateHeight = useCallback(() => {
520
534
  const iframe = iframeRef.current;
521
535
  const doc = iframe === null || iframe === void 0 ? void 0 : iframe.contentDocument;
@@ -529,10 +543,11 @@ const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef })
529
543
  if (!iframe)
530
544
  return;
531
545
  const doc = iframe.contentDocument;
546
+ cloneGlobals(iframe.contentWindow);
532
547
  injectStyles(doc);
533
548
  setIframeBody(doc.body);
534
549
  updateHeight();
535
- // Observe body size changes
550
+ // Observe body mutations & size
536
551
  if ("ResizeObserver" in window) {
537
552
  resizeObserver.current = new ResizeObserver(updateHeight);
538
553
  resizeObserver.current.observe(doc.body);
@@ -543,7 +558,9 @@ const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef })
543
558
  const iframe = iframeRef.current;
544
559
  if (!iframe)
545
560
  return;
561
+ // Attach onLoad
546
562
  iframe.addEventListener("load", handleLoad);
563
+ // If already loaded
547
564
  if (((_a = iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.readyState) === "complete") {
548
565
  handleLoad();
549
566
  }
@@ -556,6 +573,7 @@ const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef })
556
573
  }
557
574
  };
558
575
  }, [iframeRef, handleLoad]);
576
+ // Update on window resize
559
577
  useEffect(() => {
560
578
  window.addEventListener("resize", updateHeight);
561
579
  return () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/react",
3
- "version": "0.3.67",
3
+ "version": "0.3.69",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {