@betterstore/react 0.3.68 → 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,11 @@
1
1
  # @betterstore/sdk
2
2
 
3
+ ## 0.3.69
4
+
5
+ ### Patch Changes
6
+
7
+ - bug fix
8
+
3
9
  ## 0.3.68
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -521,7 +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
- const motionRef = React.useRef(null);
524
+ React.useRef(null);
525
525
  const resizeObserver = React.useRef();
526
526
  const injectStyles = React.useCallback((doc) => {
527
527
  var _a;
@@ -534,21 +534,25 @@ const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
534
534
  doc.head.appendChild(styleEl);
535
535
  styleRef.current = styleEl;
536
536
  }, []);
537
- const injectMotion = React.useCallback((doc) => {
538
- var _a;
539
- // Clean up previous style
540
- if ((_a = motionRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) {
541
- motionRef.current.parentNode.removeChild(motionRef.current);
542
- }
543
- const script = doc.createElement("script");
544
- script.type = "module";
545
- script.textContent = `
546
- import { motion } from 'https://esm.sh/motion';
547
- window.Motion = motion;
548
- `;
549
- doc.head.appendChild(script);
550
- motionRef.current = script;
551
- }, []);
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
+ };
552
556
  const updateHeight = React.useCallback(() => {
553
557
  const iframe = iframeRef.current;
554
558
  const doc = iframe === null || iframe === void 0 ? void 0 : iframe.contentDocument;
@@ -562,7 +566,7 @@ const IframeWrapper = React.memo(({ children, iframeRef, wrapperRef }) => {
562
566
  if (!iframe)
563
567
  return;
564
568
  const doc = iframe.contentDocument;
565
- injectMotion(doc);
569
+ cloneGlobals(iframe.contentWindow);
566
570
  injectStyles(doc);
567
571
  setIframeBody(doc.body);
568
572
  updateHeight();
package/dist/index.mjs CHANGED
@@ -498,7 +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
- const motionRef = useRef(null);
501
+ useRef(null);
502
502
  const resizeObserver = useRef();
503
503
  const injectStyles = useCallback((doc) => {
504
504
  var _a;
@@ -511,21 +511,25 @@ const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef })
511
511
  doc.head.appendChild(styleEl);
512
512
  styleRef.current = styleEl;
513
513
  }, []);
514
- const injectMotion = useCallback((doc) => {
515
- var _a;
516
- // Clean up previous style
517
- if ((_a = motionRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) {
518
- motionRef.current.parentNode.removeChild(motionRef.current);
519
- }
520
- const script = doc.createElement("script");
521
- script.type = "module";
522
- script.textContent = `
523
- import { motion } from 'https://esm.sh/motion';
524
- window.Motion = motion;
525
- `;
526
- doc.head.appendChild(script);
527
- motionRef.current = script;
528
- }, []);
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
+ };
529
533
  const updateHeight = useCallback(() => {
530
534
  const iframe = iframeRef.current;
531
535
  const doc = iframe === null || iframe === void 0 ? void 0 : iframe.contentDocument;
@@ -539,7 +543,7 @@ const IframeWrapper = React__default.memo(({ children, iframeRef, wrapperRef })
539
543
  if (!iframe)
540
544
  return;
541
545
  const doc = iframe.contentDocument;
542
- injectMotion(doc);
546
+ cloneGlobals(iframe.contentWindow);
543
547
  injectStyles(doc);
544
548
  setIframeBody(doc.body);
545
549
  updateHeight();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterstore/react",
3
- "version": "0.3.68",
3
+ "version": "0.3.69",
4
4
  "description": "E-commerce for Developers",
5
5
  "private": false,
6
6
  "publishConfig": {