@adobe/uix-host-react 0.7.1-nightly.20230228 → 0.8.0
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/dist/components/GuestUIFrame.d.ts +14 -11
 - package/dist/components/GuestUIFrame.d.ts.map +1 -1
 - package/dist/extension-context.d.ts +3 -0
 - package/dist/extension-context.d.ts.map +1 -1
 - package/dist/index.js +68 -34
 - package/dist/index.js.map +1 -1
 - package/package.json +3 -3
 - package/src/components/GuestUIFrame.tsx +75 -36
 - package/src/extension-context.ts +3 -0
 
| 
         @@ -1,25 +1,33 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import  
     | 
| 
       2 
     | 
    
         
            -
            import type {  
     | 
| 
      
 1 
     | 
    
         
            +
            import { UIFrameRect, VirtualApi } from "@adobe/uix-core";
         
     | 
| 
      
 2 
     | 
    
         
            +
            import type { IframeHTMLAttributes } from "react";
         
     | 
| 
       3 
3 
     | 
    
         
             
            import type { AttrTokens, SandboxToken } from "@adobe/uix-host";
         
     | 
| 
      
 4 
     | 
    
         
            +
            /**
         
     | 
| 
      
 5 
     | 
    
         
            +
             * @internal
         
     | 
| 
      
 6 
     | 
    
         
            +
             */
         
     | 
| 
      
 7 
     | 
    
         
            +
            declare type ReactIframeProps = IframeHTMLAttributes<HTMLIFrameElement>;
         
     | 
| 
       4 
8 
     | 
    
         
             
            /**
         
     | 
| 
       5 
9 
     | 
    
         
             
             * @public
         
     | 
| 
       6 
10 
     | 
    
         
             
             */
         
     | 
| 
       7 
     | 
    
         
            -
            declare type FrameProps = Omit< 
     | 
| 
      
 11 
     | 
    
         
            +
            declare type FrameProps = Omit<ReactIframeProps, "sandbox">;
         
     | 
| 
       8 
12 
     | 
    
         
             
            /** @public */
         
     | 
| 
       9 
13 
     | 
    
         
             
            export interface GuestUIProps extends FrameProps {
         
     | 
| 
       10 
14 
     | 
    
         
             
                guestId: string;
         
     | 
| 
       11 
15 
     | 
    
         
             
                /**
         
     | 
| 
       12 
16 
     | 
    
         
             
                 * Receives the Penpal context when the frame is mounted.
         
     | 
| 
       13 
17 
     | 
    
         
             
                 */
         
     | 
| 
       14 
     | 
    
         
            -
                onConnect 
     | 
| 
      
 18 
     | 
    
         
            +
                onConnect?: () => void;
         
     | 
| 
       15 
19 
     | 
    
         
             
                /**
         
     | 
| 
       16 
20 
     | 
    
         
             
                 * Called when the frame disconnects and unmounts.
         
     | 
| 
       17 
21 
     | 
    
         
             
                 */
         
     | 
| 
       18 
     | 
    
         
            -
                onDisconnect 
     | 
| 
      
 22 
     | 
    
         
            +
                onDisconnect?: () => void;
         
     | 
| 
       19 
23 
     | 
    
         
             
                /**
         
     | 
| 
       20 
24 
     | 
    
         
             
                 * Called when the connection process throws an exception
         
     | 
| 
       21 
25 
     | 
    
         
             
                 */
         
     | 
| 
       22 
26 
     | 
    
         
             
                onConnectionError?: (error: Error) => void;
         
     | 
| 
      
 27 
     | 
    
         
            +
                /**
         
     | 
| 
      
 28 
     | 
    
         
            +
                 * Called when the document in the iframe changes size.
         
     | 
| 
      
 29 
     | 
    
         
            +
                 */
         
     | 
| 
      
 30 
     | 
    
         
            +
                onResize?: (dimensions: UIFrameRect) => void;
         
     | 
| 
       23 
31 
     | 
    
         
             
                /**
         
     | 
| 
       24 
32 
     | 
    
         
             
                 * Additional sandbox attributes GuestUIFrame might need.
         
     | 
| 
       25 
33 
     | 
    
         
             
                 */
         
     | 
| 
         @@ -32,17 +40,12 @@ export interface GuestUIProps extends FrameProps { 
     | 
|
| 
       32 
40 
     | 
    
         
             
                 * Host methods to provide only to the guest inside this iframe.
         
     | 
| 
       33 
41 
     | 
    
         
             
                 */
         
     | 
| 
       34 
42 
     | 
    
         
             
                methods?: VirtualApi;
         
     | 
| 
       35 
     | 
    
         
            -
                /**
         
     | 
| 
       36 
     | 
    
         
            -
                 *
         
     | 
| 
       37 
     | 
    
         
            -
                 * @defaultValue "100%"
         
     | 
| 
       38 
     | 
    
         
            -
                 */
         
     | 
| 
       39 
     | 
    
         
            -
                width: FrameProps["width"];
         
     | 
| 
       40 
43 
     | 
    
         
             
            }
         
     | 
| 
       41 
44 
     | 
    
         
             
            /**
         
     | 
| 
       42 
45 
     | 
    
         
             
             * An iframe that attaches to a running GuestServer, to display visible UI pages
         
     | 
| 
       43 
46 
     | 
    
         
             
             * delivered by the Extension server.
         
     | 
| 
       44 
47 
     | 
    
         
             
             * @public
         
     | 
| 
       45 
48 
     | 
    
         
             
             */
         
     | 
| 
       46 
     | 
    
         
            -
            export declare  
     | 
| 
      
 49 
     | 
    
         
            +
            export declare const GuestUIFrame: ({ guestId, src, onConnect, onDisconnect, onConnectionError, onResize, methods, sandbox, style, ...customIFrameProps }: GuestUIProps) => JSX.Element;
         
     | 
| 
       47 
50 
     | 
    
         
             
            export default GuestUIFrame;
         
     | 
| 
       48 
51 
     | 
    
         
             
            //# sourceMappingURL=GuestUIFrame.d.ts.map
         
     | 
| 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {"version":3,"file":"GuestUIFrame.d.ts","sourceRoot":"","sources":["../../src/components/GuestUIFrame.tsx"],"names":[],"mappings":"AAYA,OAAO, 
     | 
| 
      
 1 
     | 
    
         
            +
            {"version":3,"file":"GuestUIFrame.d.ts","sourceRoot":"","sources":["../../src/components/GuestUIFrame.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAoB,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGhE;;GAEG;AACH,aAAK,gBAAgB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEhE;;GAEG;AACH,aAAK,UAAU,GAAG,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAEpD,cAAc;AACd,MAAM,WAAW,YAAa,SAAQ,UAAU;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B;;OAEG;IACH,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,KAAK,IAAI,CAAC;IAC7C;;OAEG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB;AAYD;;;;GAIG;AACH,eAAO,MAAM,YAAY,0HAWtB,YAAY,gBAsFd,CAAC;AACF,eAAe,YAAY,CAAC"}
         
     | 
| 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {"version":3,"file":"extension-context.d.ts","sourceRoot":"","sources":["../src/extension-context.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,eAAO,MAAM,gBAAgB,+BAA6C,CAAC"}
         
     | 
| 
      
 1 
     | 
    
         
            +
            {"version":3,"file":"extension-context.d.ts","sourceRoot":"","sources":["../src/extension-context.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,gBAAgB,+BAA6C,CAAC"}
         
     | 
    
        package/dist/index.js
    CHANGED
    
    | 
         @@ -3,6 +3,10 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            var uixHost = require('@adobe/uix-host');
         
     | 
| 
       4 
4 
     | 
    
         
             
            var React = require('react');
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
      
 6 
     | 
    
         
            +
            function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            var React__default = /*#__PURE__*/_interopDefault(React);
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
       6 
10 
     | 
    
         
             
            // src/index.ts
         
     | 
| 
       7 
11 
     | 
    
         
             
            var ExtensionContext = React.createContext({});
         
     | 
| 
       8 
12 
     | 
    
         | 
| 
         @@ -50,9 +54,7 @@ function Extensible({ 
     | 
|
| 
       50 
54 
     | 
    
         
             
              if (!host) {
         
     | 
| 
       51 
55 
     | 
    
         
             
                return null;
         
     | 
| 
       52 
56 
     | 
    
         
             
              }
         
     | 
| 
       53 
     | 
    
         
            -
              return /* @__PURE__ */  
     | 
| 
       54 
     | 
    
         
            -
                value: host
         
     | 
| 
       55 
     | 
    
         
            -
              }, children);
         
     | 
| 
      
 57 
     | 
    
         
            +
              return /* @__PURE__ */ React__default.default.createElement(ExtensionContext.Provider, { value: host }, children);
         
     | 
| 
       56 
58 
     | 
    
         
             
            }
         
     | 
| 
       57 
59 
     | 
    
         
             
            var OutsideOfExtensionContextError = class extends Error {
         
     | 
| 
       58 
60 
     | 
    
         
             
              constructor(msg) {
         
     | 
| 
         @@ -74,67 +76,99 @@ function useHost() { 
     | 
|
| 
       74 
76 
     | 
    
         
             
              }
         
     | 
| 
       75 
77 
     | 
    
         
             
              return { error: void 0, host };
         
     | 
| 
       76 
78 
     | 
    
         
             
            }
         
     | 
| 
       77 
     | 
    
         
            -
            var  
     | 
| 
      
 79 
     | 
    
         
            +
            var defaultIFrameProps = {
         
     | 
| 
       78 
80 
     | 
    
         
             
              width: "100%",
         
     | 
| 
       79 
81 
     | 
    
         
             
              height: "100%",
         
     | 
| 
       80 
82 
     | 
    
         
             
              style: {
         
     | 
| 
       81 
83 
     | 
    
         
             
                border: "none"
         
     | 
| 
       82 
84 
     | 
    
         
             
              }
         
     | 
| 
       83 
85 
     | 
    
         
             
            };
         
     | 
| 
       84 
     | 
    
         
            -
            var defaultSandbox = "allow-scripts";
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
            var defaultSandbox = "allow-scripts allow-forms allow-same-origin";
         
     | 
| 
      
 87 
     | 
    
         
            +
            var GuestUIFrame = ({
         
     | 
| 
       86 
88 
     | 
    
         
             
              guestId,
         
     | 
| 
       87 
89 
     | 
    
         
             
              src = "",
         
     | 
| 
       88 
90 
     | 
    
         
             
              onConnect,
         
     | 
| 
       89 
91 
     | 
    
         
             
              onDisconnect,
         
     | 
| 
       90 
92 
     | 
    
         
             
              onConnectionError,
         
     | 
| 
      
 93 
     | 
    
         
            +
              onResize,
         
     | 
| 
       91 
94 
     | 
    
         
             
              methods,
         
     | 
| 
       92 
95 
     | 
    
         
             
              sandbox = "",
         
     | 
| 
       93 
     | 
    
         
            -
               
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
      
 96 
     | 
    
         
            +
              style,
         
     | 
| 
      
 97 
     | 
    
         
            +
              ...customIFrameProps
         
     | 
| 
      
 98 
     | 
    
         
            +
            }) => {
         
     | 
| 
      
 99 
     | 
    
         
            +
              const ref = React.useRef();
         
     | 
| 
       95 
100 
     | 
    
         
             
              const { host } = useHost();
         
     | 
| 
       96 
101 
     | 
    
         
             
              if (!host) {
         
     | 
| 
       97 
102 
     | 
    
         
             
                return null;
         
     | 
| 
       98 
103 
     | 
    
         
             
              }
         
     | 
| 
       99 
104 
     | 
    
         
             
              const guest = host.guests.get(guestId);
         
     | 
| 
       100 
105 
     | 
    
         
             
              const frameUrl = new URL(src, guest.url.href);
         
     | 
| 
       101 
     | 
    
         
            -
               
     | 
| 
       102 
     | 
    
         
            -
                if ( 
     | 
| 
      
 106 
     | 
    
         
            +
              React.useEffect(() => {
         
     | 
| 
      
 107 
     | 
    
         
            +
                if (ref.current) {
         
     | 
| 
      
 108 
     | 
    
         
            +
                  let mounted = true;
         
     | 
| 
      
 109 
     | 
    
         
            +
                  let connection;
         
     | 
| 
      
 110 
     | 
    
         
            +
                  const connectionFrame = ref.current;
         
     | 
| 
       103 
111 
     | 
    
         
             
                  if (methods) {
         
     | 
| 
       104 
112 
     | 
    
         
             
                    guest.provide(methods);
         
     | 
| 
       105 
113 
     | 
    
         
             
                  }
         
     | 
| 
       106 
     | 
    
         
            -
                  const  
     | 
| 
       107 
     | 
    
         
            -
                   
     | 
| 
       108 
     | 
    
         
            -
                     
     | 
| 
      
 114 
     | 
    
         
            +
                  const connecting = guest.attachUI(connectionFrame);
         
     | 
| 
      
 115 
     | 
    
         
            +
                  connecting.then((c) => {
         
     | 
| 
      
 116 
     | 
    
         
            +
                    connection = c;
         
     | 
| 
      
 117 
     | 
    
         
            +
                    if (!mounted) {
         
     | 
| 
      
 118 
     | 
    
         
            +
                      c.tunnel.destroy();
         
     | 
| 
      
 119 
     | 
    
         
            +
                    } else if (onConnect) {
         
     | 
| 
       109 
120 
     | 
    
         
             
                      onConnect();
         
     | 
| 
       110 
121 
     | 
    
         
             
                    }
         
     | 
| 
       111 
122 
     | 
    
         
             
                  }).catch((error) => {
         
     | 
| 
       112 
     | 
    
         
            -
                    if ( 
     | 
| 
       113 
     | 
    
         
            -
                       
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
                       
     | 
| 
      
 123 
     | 
    
         
            +
                    if (mounted && !connection && connectionFrame === ref.current) {
         
     | 
| 
      
 124 
     | 
    
         
            +
                      const frameError = new Error(
         
     | 
| 
      
 125 
     | 
    
         
            +
                        `GuestUIFrame connection failed: ${error && error.stack || error}`
         
     | 
| 
      
 126 
     | 
    
         
            +
                      );
         
     | 
| 
      
 127 
     | 
    
         
            +
                      Object.assign(frameError, {
         
     | 
| 
      
 128 
     | 
    
         
            +
                        original: error,
         
     | 
| 
      
 129 
     | 
    
         
            +
                        ref,
         
     | 
| 
      
 130 
     | 
    
         
            +
                        guest,
         
     | 
| 
      
 131 
     | 
    
         
            +
                        host
         
     | 
| 
      
 132 
     | 
    
         
            +
                      });
         
     | 
| 
      
 133 
     | 
    
         
            +
                      if (onConnectionError)
         
     | 
| 
      
 134 
     | 
    
         
            +
                        onConnectionError(frameError);
         
     | 
| 
      
 135 
     | 
    
         
            +
                    }
         
     | 
| 
       116 
136 
     | 
    
         
             
                  });
         
     | 
| 
       117 
     | 
    
         
            -
                  return  
     | 
| 
       118 
     | 
    
         
            -
                     
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                       
     | 
| 
      
 137 
     | 
    
         
            +
                  return () => {
         
     | 
| 
      
 138 
     | 
    
         
            +
                    mounted = false;
         
     | 
| 
      
 139 
     | 
    
         
            +
                    if (connection) {
         
     | 
| 
      
 140 
     | 
    
         
            +
                      connection.tunnel.destroy();
         
     | 
| 
       121 
141 
     | 
    
         
             
                    }
         
     | 
| 
       122 
142 
     | 
    
         
             
                  };
         
     | 
| 
       123 
143 
     | 
    
         
             
                }
         
     | 
| 
       124 
144 
     | 
    
         
             
              }, []);
         
     | 
| 
       125 
     | 
    
         
            -
               
     | 
| 
       126 
     | 
    
         
            -
                 
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
            }
         
     | 
| 
      
 145 
     | 
    
         
            +
              React.useEffect(() => {
         
     | 
| 
      
 146 
     | 
    
         
            +
                if (ref.current && onResize) {
         
     | 
| 
      
 147 
     | 
    
         
            +
                  const currentFrame = ref.current;
         
     | 
| 
      
 148 
     | 
    
         
            +
                  return guest.addEventListener(
         
     | 
| 
      
 149 
     | 
    
         
            +
                    "guestresize",
         
     | 
| 
      
 150 
     | 
    
         
            +
                    ({ detail: { guestPort, iframe, dimensions } }) => {
         
     | 
| 
      
 151 
     | 
    
         
            +
                      if (guestPort.id === guest.id && iframe === currentFrame) {
         
     | 
| 
      
 152 
     | 
    
         
            +
                        onResize(dimensions);
         
     | 
| 
      
 153 
     | 
    
         
            +
                      }
         
     | 
| 
      
 154 
     | 
    
         
            +
                    }
         
     | 
| 
      
 155 
     | 
    
         
            +
                  );
         
     | 
| 
      
 156 
     | 
    
         
            +
                }
         
     | 
| 
      
 157 
     | 
    
         
            +
              }, [ref.current, guest.id, onResize]);
         
     | 
| 
      
 158 
     | 
    
         
            +
              return /* @__PURE__ */ React__default.default.createElement(
         
     | 
| 
      
 159 
     | 
    
         
            +
                "iframe",
         
     | 
| 
      
 160 
     | 
    
         
            +
                {
         
     | 
| 
      
 161 
     | 
    
         
            +
                  ...defaultIFrameProps,
         
     | 
| 
      
 162 
     | 
    
         
            +
                  ref,
         
     | 
| 
      
 163 
     | 
    
         
            +
                  src: frameUrl.href,
         
     | 
| 
      
 164 
     | 
    
         
            +
                  name: `uix-guest-${guest.id}`,
         
     | 
| 
      
 165 
     | 
    
         
            +
                  sandbox: sandbox ? uixHost.makeSandboxAttrs(defaultSandbox, sandbox).join(" ") : defaultSandbox,
         
     | 
| 
      
 166 
     | 
    
         
            +
                  style: style ? { ...style, ...defaultIFrameProps.style } : defaultIFrameProps.style,
         
     | 
| 
      
 167 
     | 
    
         
            +
                  ...customIFrameProps,
         
     | 
| 
      
 168 
     | 
    
         
            +
                  ...uixHost.requiredIframeProps
         
     | 
| 
      
 169 
     | 
    
         
            +
                }
         
     | 
| 
      
 170 
     | 
    
         
            +
              );
         
     | 
| 
      
 171 
     | 
    
         
            +
            };
         
     | 
| 
       138 
172 
     | 
    
         
             
            var NO_EXTENSIONS = [];
         
     | 
| 
       139 
173 
     | 
    
         
             
            function useExtensions(configFactory, deps = []) {
         
     | 
| 
       140 
174 
     | 
    
         
             
              const { host, error } = useHost();
         
     | 
    
        package/dist/index.js.map
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {"version":3,"sources":["../src/index.ts","../src/components/Extensible.tsx","../src/extension-context.ts","../src/components/GuestUIFrame.tsx","../src/hooks/useHost.ts","../src/hooks/useExtensions.ts"],"names":["host","React","Host","useCallback","useEffect","useMemo","useState"],"mappings":";AAYA,cAAc;;;ACAd,OAAO,SAAS,UAAU,iBAA0B;AASpD,SAAS,YAAY;;;ACNrB,SAAS,qBAAqB;AAGvB,IAAM,mBAAmB,cAAoB,CAAC,CAAoB;;;AD2BzE,SAAS,uBACP,MACA,MACA;AACA,QAAM,OAAO,OAAO,KAAK,IAAI,EAAE,KAAK;AACpC,QAAM,OAAO,OAAO,KAAK,IAAI,EAAE,KAAK;AACpC,SACE,KAAK,WAAW,KAAK,UAAU,KAAK,KAAK,CAAC,IAAI,UAAU,OAAO,KAAK,MAAM;AAE9E;AAkBO,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AACrC,QAAM,WAAW,WAAW,OAAO,SAAS,QAAQ;AAEpD,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,CAAC,CAAC;AAC/C,YAAU,MAAM;AACd,uBAAmB,EAChB,KAAK,CAAC,WAAgC;AACrC;AAAA,QAAc,CAAC,SACb,uBAAuB,MAAM,MAAM,IAAI,SAAS;AAAA,MAClD;AAAA,IACF,CAAC,EACA,MAAM,CAAC,MAAuB;AAC7B,cAAQ,MAAM,uCAAuC,CAAC;AAAA,IACxD,CAAC;AAAA,EACL,GAAG,CAAC,kBAAkB,CAAC;AAEvB,QAAM,CAAC,MAAM,OAAO,IAAI,SAAe;AACvC,YAAU,MAAM;AACd,aAAS,SAAS,KAAa;AAC7B,aAAO,CAAC,MAAuB;AAC7B,cAAM,QAAQ,aAAa,QAAQ,IAAI,IAAI,MAAM,OAAO,CAAC,CAAC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C,MAAM,GAAG,IAAI;AAC/B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,WAAW;AAAA,EACb,IAAID,SAAQ,MAAM,cAAc,IAAI,GAAG,QAAQ;AAE/C,QAAM,gBAAgBF,aAAY,MAAM;AACtC,UAAM,gBAAgB,CAAC;AACvB,UAAM,SAAS,KAAK,gBAAgB,QAAQ;AAC5C,eAAW,SAAS,QAAQ;AAC1B,UAAI,UAAU;AACZ,cAAM,QAAQ,QAAQ;AAAA,MACxB;AACA,oBAAc,KAAK,KAAkD;AAAA,IACvE;AACA,WAAO,cAAc,WAAW,IAAI,gBAAgB;AAAA,EACtD,GAAG,CAAC,GAAG,UAAU,QAAQ,CAAC;AAE1B,QAAM,YAAYA;AAAA,IAChB,CAAC,YAA2B;AAC1B,YAAM,YAAY,aAAa,QAAQ,kBAAkB;AACzD,WAAK,iBAAiB,WAAW,OAAO;AACxC,aAAO,MAAM,KAAK,oBAAoB,WAAW,OAAO;AAAA,IAC1D;AAAA,IACA,CAAC,GAAG,UAAU,QAAQ;AAAA,EACxB;AAEA,QAAM,CAAC,YAAY,aAAa,IAAIG,UAAS,MAAM,cAAc,CAAC;AAClE,EAAAF,WAAU,MAAM;AACd,WAAO,UAAU,MAAM;AACrB,oBAAc,cAAc,CAAC;AAAA,IAC/B,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,aAAa,CAAC;AAE7B,QAAM,CAAC,WAAW,YAAY,IAAIE,UAAgB;AAClD,EAAAF;AAAA,IACE,MACE,KAAK;AAAA,MACH;AAAA,MACA,CAAC,UACC,aAAa,MAAM,OAAO,KAAK;AAAA,IACnC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,YAAY,SAAS,CAAC,KAAK,SAAS,OAAO,UAAU;AAChE","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from \"@adobe/uix-host\";\nexport * from \"./components/index.js\";\nexport * from \"./hooks/index.js\";\nexport * from \"./extension-context\";\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport React, { useState, useEffect, useMemo } from \"react\";\nimport type { PropsWithChildren } from \"react\";\nimport type {\n  InstalledExtensions,\n  ExtensionsProvider,\n  HostConfig,\n  PortOptions,\n  SharedContextValues,\n} from \"@adobe/uix-host\";\nimport { Host } from \"@adobe/uix-host\";\nimport { ExtensionContext } from \"../extension-context.js\";\n\n/** @public */\nexport interface ExtensibleProps extends Omit<HostConfig, \"hostName\"> {\n  /**\n   * Unique name for identifying this extensible app. May be used as metadata in\n   * extension registry in the future.\n   */\n  appName?: string;\n  /**\n   * Function which returns a promise for the full list of extensions.\n   */\n  extensionsProvider: ExtensionsProvider;\n  /**\n   * {@inheritDoc HostConfig.guestOptions}\n   */\n  guestOptions?: PortOptions;\n  /**\n   * {@inheritDoc HostConfig.sharedContext}\n   */\n  sharedContext?: SharedContextValues;\n}\n\nfunction areExtensionsDifferent(\n  set1: InstalledExtensions,\n  set2: InstalledExtensions\n) {\n  const ids1 = Object.keys(set1).sort();\n  const ids2 = Object.keys(set2).sort();\n  return (\n    ids1.length !== ids2.length || ids1.some((id, index) => id !== ids2[index])\n  );\n}\n\n/**\n * Declares an extensible area in an app, and provides host and extension\n * objects to all descendents. The {@link useExtensions} hook can only be called\n * in a descendent of this component.\n *\n * @remarks\n * For many apps, there will be only one Extensible provider, fairly high in the\n * component tree. It is a context provider component that may be bundled with\n * other context providers in your app architecture.\n *\n * Each Extensible element creates one {@link @adobe/uix-host#Host} object and\n * one call to an extensions provider. If multiple Extensible elements are used,\n * this may cause redundant calls. Such a design should be carefully considered.\n *\n * @public\n */\nexport function Extensible({\n  appName,\n  children,\n  extensionsProvider,\n  guestOptions,\n  runtimeContainer,\n  debug,\n  sharedContext,\n}: PropsWithChildren<ExtensibleProps>) {\n  const hostName = appName || window.location.host || \"mainframe\";\n\n  const [extensions, setExtensions] = useState({});\n  useEffect(() => {\n    extensionsProvider()\n      .then((loaded: InstalledExtensions) => {\n        setExtensions((prev) =>\n          areExtensionsDifferent(prev, loaded) ? loaded : prev\n        );\n      })\n      .catch((e: Error | unknown) => {\n        console.error(\"Fetching list of extensions failed!\", e);\n      });\n  }, [extensionsProvider]);\n\n  const [host, setHost] = useState<Host>();\n  useEffect(() => {\n    function logError(msg: string) {\n      return (e: Error | unknown) => {\n        const error = e instanceof Error ? e : new Error(String(e));\n        console.error(msg, error, extensions, guestOptions);\n      };\n    }\n\n    const host = new Host({ debug, hostName, runtimeContainer, sharedContext });\n    setHost(host);\n\n    if (!Object.entries(extensions).length) {\n      return;\n    }\n\n    host\n      .load(extensions, guestOptions)\n      .catch(logError(\"Load of extensions failed!\"));\n  }, [debug, hostName, runtimeContainer, extensions]);\n\n  // skip render before host is initialized\n  if (!host) {\n    return null;\n  }\n\n  return (\n    <ExtensionContext.Provider value={host}>\n      {children}\n    </ExtensionContext.Provider>\n  );\n}\nexport default Extensible;\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/**\n * @hidden\n */\nimport { createContext } from \"react\";\nimport { Host } from \"@adobe/uix-host\";\n\nexport const ExtensionContext = createContext<Host>({} as unknown as Host);\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type { VirtualApi } from \"@adobe/uix-core\";\nimport React, { useCallback } from \"react\";\nimport type { PropsWithChildren, IframeHTMLAttributes } from \"react\";\nimport { useHost } from \"../hooks/useHost.js\";\nimport type { AttrTokens, SandboxToken } from \"@adobe/uix-host\";\nimport { makeSandboxAttrs, requiredIframeProps } from \"@adobe/uix-host\";\n\n/**\n * @public\n */\ntype FrameProps = Omit<IframeHTMLAttributes<HTMLIFrameElement>, \"sandbox\">;\n\n/** @public */\nexport interface GuestUIProps extends FrameProps {\n  guestId: string;\n  /**\n   * Receives the Penpal context when the frame is mounted.\n   */\n  onConnect: () => unknown;\n  /**\n   * Called when the frame disconnects and unmounts.\n   */\n  onDisconnect: () => unknown;\n  /**\n   * Called when the connection process throws an exception\n   */\n  onConnectionError?: (error: Error) => void;\n  /**\n   * Additional sandbox attributes GuestUIFrame might need.\n   */\n  sandbox?: AttrTokens<SandboxToken>;\n  /**\n   * Optional custom URL or path.\n   */\n  src: string;\n  /**\n   * Host methods to provide only to the guest inside this iframe.\n   */\n  methods?: VirtualApi;\n\n  /**\n   *\n   * @defaultValue \"100%\"\n   */\n  width: FrameProps[\"width\"];\n}\n\nconst defaultFrameProps: FrameProps = {\n  width: \"100%\",\n  height: \"100%\",\n  style: {\n    border: \"none\",\n  },\n};\n\nconst defaultSandbox = \"allow-scripts\";\n\n/**\n * An iframe that attaches to a running GuestServer, to display visible UI pages\n * delivered by the Extension server.\n * @public\n */\nexport function GuestUIFrame({\n  guestId,\n  src = \"\",\n  onConnect,\n  onDisconnect,\n  onConnectionError,\n  methods,\n  sandbox = \"\",\n  ...customFrameProps\n}: PropsWithChildren<GuestUIProps>) {\n  const { host } = useHost();\n  if (!host) {\n    return null;\n  }\n  const guest = host.guests.get(guestId);\n  const frameUrl = new URL(src, guest.url.href);\n\n  const ref = useCallback((iframe: HTMLIFrameElement) => {\n    if (iframe) {\n      if (methods) {\n        guest.provide(methods);\n      }\n      const connection = guest.attachUI(iframe);\n      connection\n        .then(() => {\n          if (onConnect) {\n            onConnect();\n          }\n        })\n        .catch((error: Error) => {\n          if (onConnectionError) onConnectionError(error);\n          else throw error;\n        });\n      return async () => {\n        if (onDisconnect) {\n          await onDisconnect();\n          return guest.unload();\n        }\n      };\n    }\n  }, []);\n\n  const frameProps = {\n    ...defaultFrameProps,\n    ...customFrameProps,\n    ...requiredIframeProps,\n  };\n\n  return (\n    <iframe\n      ref={ref}\n      src={frameUrl.href}\n      name={`uix-guest-${guest.id}`}\n      sandbox={\n        sandbox\n          ? makeSandboxAttrs(defaultSandbox, sandbox).join(\" \")\n          : defaultSandbox\n      }\n      {...frameProps}\n    />\n  );\n}\nexport default GuestUIFrame;\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { useContext } from \"react\";\nimport { Host } from \"@adobe/uix-host\";\nimport { ExtensionContext } from \"../extension-context.js\";\n\n/**\n * @public\n */\nexport class OutsideOfExtensionContextError extends Error {\n  outsideOfExtensionContext: boolean;\n  constructor(msg: string) {\n    super(msg);\n    this.outsideOfExtensionContext = true;\n    Object.setPrototypeOf(this, OutsideOfExtensionContextError.prototype);\n  }\n}\n\n/** @public */\ntype UseHostResponse =\n  | { host: undefined; error: Error }\n  | { host: Host; error: undefined };\n\n/**\n * Retrieve the {@link @adobe/uix-host#Host} object hosting all extensions inside the current parent provider.\n *\n * @remarks Returns a `{ host, error }` tuple, not the host object directly.\n * @beta\n */\nexport function useHost(): UseHostResponse {\n  const host = useContext(ExtensionContext);\n  if (!(host instanceof Host)) {\n    const error = new OutsideOfExtensionContextError(\n      \"Attempt to use extensions outside of ExtensionContext. Wrap extensible part of application with Extensible component.\"\n    );\n    return {\n      host: undefined,\n      error,\n    };\n  }\n  return { error: undefined, host };\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type {\n  GuestConnection,\n  GuestApis,\n  RemoteGuestApis,\n  VirtualApi,\n} from \"@adobe/uix-core\";\n\nimport { Host, HostEvents } from \"@adobe/uix-host\";\nimport type { CapabilitySpec } from \"@adobe/uix-host\";\nimport { useHost } from \"./useHost.js\";\n\n/**\n * @internal\n */\nexport interface TypedGuestConnection<T extends GuestApis>\n  extends GuestConnection {\n  id: GuestConnection[\"id\"];\n  apis: RemoteGuestApis<T>;\n}\n\n/** @public */\nexport interface UseExtensionsConfig<\n  Incoming extends GuestApis,\n  Outgoing extends VirtualApi\n> {\n  /**\n   * A {@link @adobe/uix-host#CapabilitySpec} describing the namespaced methods\n   * extensions must implement to be used by this component.\n   *\n   * @remarks\n   * This declaration is used to filter the extensions that will be\n   * returned; if they don't implement those methods, they will be filtered out.\n   */\n  requires?: CapabilitySpec<Incoming>;\n  /**\n   * A namespaced object of methods which extensions will be able to call.\n   *\n   * @remarks This is the counterpart of `requires`; in `requires`, the you\n   * describes methods the extension must implement that your host code will\n   * call, and in `provides`, you implement host methods that extensions will be\n   * able to call.\n   *\n   * Most cases for host-side methods will use the state of the component. This\n   * can cause unexpected bugs in React if the config callback is run on every\n   * render. **useExtensions caches the config callback by default!**\n   * So remember to pass a deps array, so that the config callback re-runs under\n   * the right conditions.\n   */\n  provides?: Outgoing;\n  /**\n   * Sets when re-render is triggered on extension load.\n   *\n   * @remarks\n   * Set to `each` to trigger a component re-render every time an individual\n   * extension loads, which may result in multiple UI updates. Set to `all` to\n   * wait until all extensions have loaded to re-render the component.\n   * @defaultValue \"each\"\n   */\n  updateOn?: \"each\" | \"all\";\n}\n\n/** @public */\nexport interface UseExtensionsResult<T extends GuestApis> {\n  /**\n   * A list of loaded guests which implement the methods specified in\n   * `requires`, represented as {@link @adobe/uix-host#Port} objects which\n   * present methods to be called.\n   */\n  extensions: TypedGuestConnection<T>[];\n  /**\n   * This is `true` until all extensions are loaded. Use for rendering spinners\n   * or other intermediate UI.\n   */\n  loading: boolean;\n  /**\n   * Populated with an Error if there were any problems during the load process.\n   */\n  error?: Error;\n}\n\nconst NO_EXTENSIONS: [] = [];\n\n/**\n * Fetch extensions which implement an API, provide them methods, and use them.\n *\n * @remarks `useExtensions` does three things at once:\n *  - Gets all extensions which implement the APIs described in the `require` field\n *  - Exposes any functions defined in the `provide` field to those extensions\n *  - Returns an object whose `extensions` property is a list of `Port` objects representing those extensions\n *\n * useExtensions will trigger a re-render when extensions load. You can choose whether it triggers that rerender as each extension loads, or only after all extensions have loaded.\n * @public\n */\nexport function useExtensions<\n  Incoming extends GuestApis,\n  Outgoing extends VirtualApi\n>(\n  configFactory: (host: Host) => UseExtensionsConfig<Incoming, Outgoing>,\n  deps: unknown[] = []\n): UseExtensionsResult<Incoming> {\n  const { host, error } = useHost();\n  if (error) {\n    return {\n      extensions: NO_EXTENSIONS,\n      loading: false,\n      error,\n    };\n  }\n\n  const baseDeps = [host, ...deps];\n  const {\n    requires,\n    provides,\n    updateOn = \"each\",\n  } = useMemo(() => configFactory(host), baseDeps);\n\n  const getExtensions = useCallback(() => {\n    const newExtensions = [];\n    const guests = host.getLoadedGuests(requires);\n    for (const guest of guests) {\n      if (provides) {\n        guest.provide(provides);\n      }\n      newExtensions.push(guest as unknown as TypedGuestConnection<Incoming>);\n    }\n    return newExtensions.length === 0 ? NO_EXTENSIONS : newExtensions;\n  }, [...baseDeps, requires]);\n\n  const subscribe = useCallback(\n    (handler: EventListener) => {\n      const eventName = updateOn === \"all\" ? \"loadallguests\" : \"guestload\";\n      host.addEventListener(eventName, handler);\n      return () => host.removeEventListener(eventName, handler);\n    },\n    [...baseDeps, updateOn]\n  );\n\n  const [extensions, setExtensions] = useState(() => getExtensions());\n  useEffect(() => {\n    return subscribe(() => {\n      setExtensions(getExtensions());\n    });\n  }, [subscribe, getExtensions]);\n\n  const [hostError, setHostError] = useState<Error>();\n  useEffect(\n    () =>\n      host.addEventListener(\n        \"error\",\n        (event: Extract<HostEvents, { detail: { error: Error } }>) =>\n          setHostError(event.detail.error)\n      ),\n    baseDeps\n  );\n\n  return { extensions, loading: !host.loading, error: hostError };\n}\n"]}
         
     | 
| 
      
 1 
     | 
    
         
            +
            {"version":3,"sources":["../src/index.ts","../src/components/Extensible.tsx","../src/extension-context.ts","../src/components/GuestUIFrame.tsx","../src/hooks/useHost.ts","../src/hooks/useExtensions.ts"],"names":["host","React","useEffect","Host","useMemo","useState"],"mappings":";AAYA,cAAc;;;ACAd,OAAO,SAAS,UAAU,iBAA0B;AASpD,SAAS,YAAY;;;ACNrB,SAAS,qBAAqB;AAMvB,IAAM,m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;AAAA,IAC/B,CAAC;AAAA,EACH,GAAG,CAAC,WAAW,aAAa,CAAC;AAE7B,QAAM,CAAC,WAAW,YAAY,IAAIG,UAAgB;AAClD,EAAAH;AAAA,IACE,MACE,KAAK;AAAA,MACH;AAAA,MACA,CAAC,UACC,aAAa,MAAM,OAAO,KAAK;AAAA,IACnC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,EAAE,YAAY,SAAS,CAAC,KAAK,SAAS,OAAO,UAAU;AAChE","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from \"@adobe/uix-host\";\nexport * from \"./components/index.js\";\nexport * from \"./hooks/index.js\";\nexport * from \"./extension-context\";\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport React, { useState, useEffect, useMemo } from \"react\";\nimport type { PropsWithChildren } from \"react\";\nimport type {\n  InstalledExtensions,\n  ExtensionsProvider,\n  HostConfig,\n  PortOptions,\n  SharedContextValues,\n} from \"@adobe/uix-host\";\nimport { Host } from \"@adobe/uix-host\";\nimport { ExtensionContext } from \"../extension-context.js\";\n\n/** @public */\nexport interface ExtensibleProps extends Omit<HostConfig, \"hostName\"> {\n  /**\n   * Unique name for identifying this extensible app. May be used as metadata in\n   * extension registry in the future.\n   */\n  appName?: string;\n  /**\n   * Function which returns a promise for the full list of extensions.\n   */\n  extensionsProvider: ExtensionsProvider;\n  /**\n   * {@inheritDoc HostConfig.guestOptions}\n   */\n  guestOptions?: PortOptions;\n  /**\n   * {@inheritDoc HostConfig.sharedContext}\n   */\n  sharedContext?: SharedContextValues;\n}\n\nfunction areExtensionsDifferent(\n  set1: InstalledExtensions,\n  set2: InstalledExtensions\n) {\n  const ids1 = Object.keys(set1).sort();\n  const ids2 = Object.keys(set2).sort();\n  return (\n    ids1.length !== ids2.length || ids1.some((id, index) => id !== ids2[index])\n  );\n}\n\n/**\n * Declares an extensible area in an app, and provides host and extension\n * objects to all descendents. The {@link useExtensions} hook can only be called\n * in a descendent of this component.\n *\n * @remarks\n * For many apps, there will be only one Extensible provider, fairly high in the\n * component tree. It is a context provider component that may be bundled with\n * other context providers in your app architecture.\n *\n * Each Extensible element creates one {@link @adobe/uix-host#Host} object and\n * one call to an extensions provider. If multiple Extensible elements are used,\n * this may cause redundant calls. Such a design should be carefully considered.\n *\n * @public\n */\nexport function Extensible({\n  appName,\n  children,\n  extensionsProvider,\n  guestOptions,\n  runtimeContainer,\n  debug,\n  sharedContext,\n}: PropsWithChildren<ExtensibleProps>) {\n  const hostName = appName || window.location.host || \"mainframe\";\n\n  const [extensions, setExtensions] = useState({});\n  useEffect(() => {\n    extensionsProvider()\n      .then((loaded: InstalledExtensions) => {\n        setExtensions((prev) =>\n          areExtensionsDifferent(prev, loaded) ? loaded : prev\n        );\n      })\n      .catch((e: Error | unknown) => {\n        console.error(\"Fetching list of extensions failed!\", e);\n      });\n  }, [extensionsProvider]);\n\n  const [host, setHost] = useState<Host>();\n  useEffect(() => {\n    function logError(msg: string) {\n      return (e: Error | unknown) => {\n        const error = e instanceof Error ? e : new Error(String(e));\n        console.error(msg, error, extensions, guestOptions);\n      };\n    }\n\n    const host = new Host({ debug, hostName, runtimeContainer, sharedContext });\n    setHost(host);\n\n    if (!Object.entries(extensions).length) {\n      return;\n    }\n\n    host\n      .load(extensions, guestOptions)\n      .catch(logError(\"Load of extensions failed!\"));\n  }, [debug, hostName, runtimeContainer, extensions]);\n\n  // skip render before host is initialized\n  if (!host) {\n    return null;\n  }\n\n  return (\n    <ExtensionContext.Provider value={host}>\n      {children}\n    </ExtensionContext.Provider>\n  );\n}\nexport default Extensible;\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/**\n * @hidden\n */\nimport { createContext } from \"react\";\nimport { Host } from \"@adobe/uix-host\";\n\n/**\n * @internal\n */\nexport const ExtensionContext = createContext<Host>({} as unknown as Host);\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { CrossRealmObject, UIFrameRect, VirtualApi } from \"@adobe/uix-core\";\nimport React, { useEffect, useRef } from \"react\";\nimport type { IframeHTMLAttributes } from \"react\";\nimport { useHost } from \"../hooks/useHost.js\";\nimport type { AttrTokens, SandboxToken } from \"@adobe/uix-host\";\nimport { makeSandboxAttrs, requiredIframeProps } from \"@adobe/uix-host\";\n\n/**\n * @internal\n */\ntype ReactIframeProps = IframeHTMLAttributes<HTMLIFrameElement>;\n\n/**\n * @public\n */\ntype FrameProps = Omit<ReactIframeProps, \"sandbox\">;\n\n/** @public */\nexport interface GuestUIProps extends FrameProps {\n  guestId: string;\n  /**\n   * Receives the Penpal context when the frame is mounted.\n   */\n  onConnect?: () => void;\n  /**\n   * Called when the frame disconnects and unmounts.\n   */\n  onDisconnect?: () => void;\n  /**\n   * Called when the connection process throws an exception\n   */\n  onConnectionError?: (error: Error) => void;\n  /**\n   * Called when the document in the iframe changes size.\n   */\n  onResize?: (dimensions: UIFrameRect) => void;\n  /**\n   * Additional sandbox attributes GuestUIFrame might need.\n   */\n  sandbox?: AttrTokens<SandboxToken>;\n  /**\n   * Optional custom URL or path.\n   */\n  src: string;\n  /**\n   * Host methods to provide only to the guest inside this iframe.\n   */\n  methods?: VirtualApi;\n}\n\nconst defaultIFrameProps: FrameProps = {\n  width: \"100%\",\n  height: \"100%\",\n  style: {\n    border: \"none\",\n  },\n};\n\nconst defaultSandbox = \"allow-scripts allow-forms allow-same-origin\";\n\n/**\n * An iframe that attaches to a running GuestServer, to display visible UI pages\n * delivered by the Extension server.\n * @public\n */\nexport const GuestUIFrame = ({\n  guestId,\n  src = \"\",\n  onConnect,\n  onDisconnect,\n  onConnectionError,\n  onResize,\n  methods,\n  sandbox = \"\",\n  style,\n  ...customIFrameProps\n}: GuestUIProps) => {\n  const ref = useRef<HTMLIFrameElement>();\n  const { host } = useHost();\n  if (!host) {\n    return null;\n  }\n  const guest = host.guests.get(guestId);\n  const frameUrl = new URL(src, guest.url.href);\n\n  useEffect(() => {\n    if (ref.current) {\n      let mounted = true;\n      let connection: CrossRealmObject<VirtualApi>;\n      const connectionFrame = ref.current;\n      if (methods) {\n        guest.provide(methods);\n      }\n      const connecting = guest.attachUI(connectionFrame);\n      connecting\n        .then((c) => {\n          connection = c;\n          if (!mounted) {\n            c.tunnel.destroy();\n          } else if (onConnect) {\n            onConnect();\n          }\n        })\n        .catch((error: Error) => {\n          if (mounted && !connection && connectionFrame === ref.current) {\n            const frameError = new Error(\n              `GuestUIFrame connection failed: ${\n                (error && error.stack) || error\n              }`\n            );\n            Object.assign(frameError, {\n              original: error,\n              ref,\n              guest,\n              host,\n            });\n            if (onConnectionError) onConnectionError(frameError);\n          }\n        });\n      return () => {\n        mounted = false;\n        if (connection) {\n          connection.tunnel.destroy();\n        }\n      };\n    }\n  }, []);\n\n  useEffect(() => {\n    if (ref.current && onResize) {\n      const currentFrame = ref.current;\n      return guest.addEventListener(\n        \"guestresize\",\n        ({ detail: { guestPort, iframe, dimensions } }) => {\n          if (guestPort.id === guest.id && iframe === currentFrame) {\n            onResize(dimensions);\n          }\n        }\n      );\n    }\n  }, [ref.current, guest.id, onResize]);\n\n  return (\n    <iframe\n      {...defaultIFrameProps}\n      ref={ref}\n      src={frameUrl.href}\n      name={`uix-guest-${guest.id}`}\n      sandbox={\n        sandbox\n          ? makeSandboxAttrs(defaultSandbox, sandbox).join(\" \")\n          : defaultSandbox\n      }\n      style={\n        style\n          ? { ...style, ...defaultIFrameProps.style }\n          : defaultIFrameProps.style\n      }\n      {...customIFrameProps}\n      {...requiredIframeProps}\n    />\n  );\n};\nexport default GuestUIFrame;\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { useContext } from \"react\";\nimport { Host } from \"@adobe/uix-host\";\nimport { ExtensionContext } from \"../extension-context.js\";\n\n/**\n * @public\n */\nexport class OutsideOfExtensionContextError extends Error {\n  outsideOfExtensionContext: boolean;\n  constructor(msg: string) {\n    super(msg);\n    this.outsideOfExtensionContext = true;\n    Object.setPrototypeOf(this, OutsideOfExtensionContextError.prototype);\n  }\n}\n\n/** @public */\ntype UseHostResponse =\n  | { host: undefined; error: Error }\n  | { host: Host; error: undefined };\n\n/**\n * Retrieve the {@link @adobe/uix-host#Host} object hosting all extensions inside the current parent provider.\n *\n * @remarks Returns a `{ host, error }` tuple, not the host object directly.\n * @beta\n */\nexport function useHost(): UseHostResponse {\n  const host = useContext(ExtensionContext);\n  if (!(host instanceof Host)) {\n    const error = new OutsideOfExtensionContextError(\n      \"Attempt to use extensions outside of ExtensionContext. Wrap extensible part of application with Extensible component.\"\n    );\n    return {\n      host: undefined,\n      error,\n    };\n  }\n  return { error: undefined, host };\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\nimport type {\n  GuestConnection,\n  GuestApis,\n  RemoteGuestApis,\n  VirtualApi,\n} from \"@adobe/uix-core\";\n\nimport { Host, HostEvents } from \"@adobe/uix-host\";\nimport type { CapabilitySpec } from \"@adobe/uix-host\";\nimport { useHost } from \"./useHost.js\";\n\n/**\n * @internal\n */\nexport interface TypedGuestConnection<T extends GuestApis>\n  extends GuestConnection {\n  id: GuestConnection[\"id\"];\n  apis: RemoteGuestApis<T>;\n}\n\n/** @public */\nexport interface UseExtensionsConfig<\n  Incoming extends GuestApis,\n  Outgoing extends VirtualApi\n> {\n  /**\n   * A {@link @adobe/uix-host#CapabilitySpec} describing the namespaced methods\n   * extensions must implement to be used by this component.\n   *\n   * @remarks\n   * This declaration is used to filter the extensions that will be\n   * returned; if they don't implement those methods, they will be filtered out.\n   */\n  requires?: CapabilitySpec<Incoming>;\n  /**\n   * A namespaced object of methods which extensions will be able to call.\n   *\n   * @remarks This is the counterpart of `requires`; in `requires`, the you\n   * describes methods the extension must implement that your host code will\n   * call, and in `provides`, you implement host methods that extensions will be\n   * able to call.\n   *\n   * Most cases for host-side methods will use the state of the component. This\n   * can cause unexpected bugs in React if the config callback is run on every\n   * render. **useExtensions caches the config callback by default!**\n   * So remember to pass a deps array, so that the config callback re-runs under\n   * the right conditions.\n   */\n  provides?: Outgoing;\n  /**\n   * Sets when re-render is triggered on extension load.\n   *\n   * @remarks\n   * Set to `each` to trigger a component re-render every time an individual\n   * extension loads, which may result in multiple UI updates. Set to `all` to\n   * wait until all extensions have loaded to re-render the component.\n   * @defaultValue \"each\"\n   */\n  updateOn?: \"each\" | \"all\";\n}\n\n/** @public */\nexport interface UseExtensionsResult<T extends GuestApis> {\n  /**\n   * A list of loaded guests which implement the methods specified in\n   * `requires`, represented as {@link @adobe/uix-host#Port} objects which\n   * present methods to be called.\n   */\n  extensions: TypedGuestConnection<T>[];\n  /**\n   * This is `true` until all extensions are loaded. Use for rendering spinners\n   * or other intermediate UI.\n   */\n  loading: boolean;\n  /**\n   * Populated with an Error if there were any problems during the load process.\n   */\n  error?: Error;\n}\n\nconst NO_EXTENSIONS: [] = [];\n\n/**\n * Fetch extensions which implement an API, provide them methods, and use them.\n *\n * @remarks `useExtensions` does three things at once:\n *  - Gets all extensions which implement the APIs described in the `require` field\n *  - Exposes any functions defined in the `provide` field to those extensions\n *  - Returns an object whose `extensions` property is a list of `Port` objects representing those extensions\n *\n * useExtensions will trigger a re-render when extensions load. You can choose whether it triggers that rerender as each extension loads, or only after all extensions have loaded.\n * @public\n */\nexport function useExtensions<\n  Incoming extends GuestApis,\n  Outgoing extends VirtualApi\n>(\n  configFactory: (host: Host) => UseExtensionsConfig<Incoming, Outgoing>,\n  deps: unknown[] = []\n): UseExtensionsResult<Incoming> {\n  const { host, error } = useHost();\n  if (error) {\n    return {\n      extensions: NO_EXTENSIONS,\n      loading: false,\n      error,\n    };\n  }\n\n  const baseDeps = [host, ...deps];\n  const {\n    requires,\n    provides,\n    updateOn = \"each\",\n  } = useMemo(() => configFactory(host), baseDeps);\n\n  const getExtensions = useCallback(() => {\n    const newExtensions = [];\n    const guests = host.getLoadedGuests(requires);\n    for (const guest of guests) {\n      if (provides) {\n        guest.provide(provides);\n      }\n      newExtensions.push(guest as unknown as TypedGuestConnection<Incoming>);\n    }\n    return newExtensions.length === 0 ? NO_EXTENSIONS : newExtensions;\n  }, [...baseDeps, requires]);\n\n  const subscribe = useCallback(\n    (handler: EventListener) => {\n      const eventName = updateOn === \"all\" ? \"loadallguests\" : \"guestload\";\n      host.addEventListener(eventName, handler);\n      return () => host.removeEventListener(eventName, handler);\n    },\n    [...baseDeps, updateOn]\n  );\n\n  const [extensions, setExtensions] = useState(() => getExtensions());\n  useEffect(() => {\n    return subscribe(() => {\n      setExtensions(getExtensions());\n    });\n  }, [subscribe, getExtensions]);\n\n  const [hostError, setHostError] = useState<Error>();\n  useEffect(\n    () =>\n      host.addEventListener(\n        \"error\",\n        (event: Extract<HostEvents, { detail: { error: Error } }>) =>\n          setHostError(event.detail.error)\n      ),\n    baseDeps\n  );\n\n  return { extensions, loading: !host.loading, error: hostError };\n}\n"]}
         
     | 
    
        package/package.json
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            {
         
     | 
| 
       2 
2 
     | 
    
         
             
              "name": "@adobe/uix-host-react",
         
     | 
| 
       3 
     | 
    
         
            -
              "version": "0. 
     | 
| 
      
 3 
     | 
    
         
            +
              "version": "0.8.0",
         
     | 
| 
       4 
4 
     | 
    
         
             
              "publishConfig": {
         
     | 
| 
       5 
5 
     | 
    
         
             
                "access": "public"
         
     | 
| 
       6 
6 
     | 
    
         
             
              },
         
     | 
| 
         @@ -18,8 +18,8 @@ 
     | 
|
| 
       18 
18 
     | 
    
         
             
              ],
         
     | 
| 
       19 
19 
     | 
    
         
             
              "bugs": "https://github.com/adobe/uix-sdk/issues",
         
     | 
| 
       20 
20 
     | 
    
         
             
              "dependencies": {
         
     | 
| 
       21 
     | 
    
         
            -
                "@adobe/uix-core": "^0. 
     | 
| 
       22 
     | 
    
         
            -
                "@adobe/uix-host": "^0. 
     | 
| 
      
 21 
     | 
    
         
            +
                "@adobe/uix-core": "^0.8.0",
         
     | 
| 
      
 22 
     | 
    
         
            +
                "@adobe/uix-host": "^0.8.0"
         
     | 
| 
       23 
23 
     | 
    
         
             
              },
         
     | 
| 
       24 
24 
     | 
    
         
             
              "files": [
         
     | 
| 
       25 
25 
     | 
    
         
             
                "README.md",
         
     | 
| 
         @@ -10,17 +10,22 @@ OF ANY KIND, either express or implied. See the License for the specific languag 
     | 
|
| 
       10 
10 
     | 
    
         
             
            governing permissions and limitations under the License.
         
     | 
| 
       11 
11 
     | 
    
         
             
            */
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            import  
     | 
| 
       14 
     | 
    
         
            -
            import React, {  
     | 
| 
       15 
     | 
    
         
            -
            import type {  
     | 
| 
      
 13 
     | 
    
         
            +
            import { CrossRealmObject, UIFrameRect, VirtualApi } from "@adobe/uix-core";
         
     | 
| 
      
 14 
     | 
    
         
            +
            import React, { useEffect, useRef } from "react";
         
     | 
| 
      
 15 
     | 
    
         
            +
            import type { IframeHTMLAttributes } from "react";
         
     | 
| 
       16 
16 
     | 
    
         
             
            import { useHost } from "../hooks/useHost.js";
         
     | 
| 
       17 
17 
     | 
    
         
             
            import type { AttrTokens, SandboxToken } from "@adobe/uix-host";
         
     | 
| 
       18 
18 
     | 
    
         
             
            import { makeSandboxAttrs, requiredIframeProps } from "@adobe/uix-host";
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
      
 20 
     | 
    
         
            +
            /**
         
     | 
| 
      
 21 
     | 
    
         
            +
             * @internal
         
     | 
| 
      
 22 
     | 
    
         
            +
             */
         
     | 
| 
      
 23 
     | 
    
         
            +
            type ReactIframeProps = IframeHTMLAttributes<HTMLIFrameElement>;
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
       20 
25 
     | 
    
         
             
            /**
         
     | 
| 
       21 
26 
     | 
    
         
             
             * @public
         
     | 
| 
       22 
27 
     | 
    
         
             
             */
         
     | 
| 
       23 
     | 
    
         
            -
            type FrameProps = Omit< 
     | 
| 
      
 28 
     | 
    
         
            +
            type FrameProps = Omit<ReactIframeProps, "sandbox">;
         
     | 
| 
       24 
29 
     | 
    
         | 
| 
       25 
30 
     | 
    
         
             
            /** @public */
         
     | 
| 
       26 
31 
     | 
    
         
             
            export interface GuestUIProps extends FrameProps {
         
     | 
| 
         @@ -28,15 +33,19 @@ export interface GuestUIProps extends FrameProps { 
     | 
|
| 
       28 
33 
     | 
    
         
             
              /**
         
     | 
| 
       29 
34 
     | 
    
         
             
               * Receives the Penpal context when the frame is mounted.
         
     | 
| 
       30 
35 
     | 
    
         
             
               */
         
     | 
| 
       31 
     | 
    
         
            -
              onConnect 
     | 
| 
      
 36 
     | 
    
         
            +
              onConnect?: () => void;
         
     | 
| 
       32 
37 
     | 
    
         
             
              /**
         
     | 
| 
       33 
38 
     | 
    
         
             
               * Called when the frame disconnects and unmounts.
         
     | 
| 
       34 
39 
     | 
    
         
             
               */
         
     | 
| 
       35 
     | 
    
         
            -
              onDisconnect 
     | 
| 
      
 40 
     | 
    
         
            +
              onDisconnect?: () => void;
         
     | 
| 
       36 
41 
     | 
    
         
             
              /**
         
     | 
| 
       37 
42 
     | 
    
         
             
               * Called when the connection process throws an exception
         
     | 
| 
       38 
43 
     | 
    
         
             
               */
         
     | 
| 
       39 
44 
     | 
    
         
             
              onConnectionError?: (error: Error) => void;
         
     | 
| 
      
 45 
     | 
    
         
            +
              /**
         
     | 
| 
      
 46 
     | 
    
         
            +
               * Called when the document in the iframe changes size.
         
     | 
| 
      
 47 
     | 
    
         
            +
               */
         
     | 
| 
      
 48 
     | 
    
         
            +
              onResize?: (dimensions: UIFrameRect) => void;
         
     | 
| 
       40 
49 
     | 
    
         
             
              /**
         
     | 
| 
       41 
50 
     | 
    
         
             
               * Additional sandbox attributes GuestUIFrame might need.
         
     | 
| 
       42 
51 
     | 
    
         
             
               */
         
     | 
| 
         @@ -49,15 +58,9 @@ export interface GuestUIProps extends FrameProps { 
     | 
|
| 
       49 
58 
     | 
    
         
             
               * Host methods to provide only to the guest inside this iframe.
         
     | 
| 
       50 
59 
     | 
    
         
             
               */
         
     | 
| 
       51 
60 
     | 
    
         
             
              methods?: VirtualApi;
         
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
              /**
         
     | 
| 
       54 
     | 
    
         
            -
               *
         
     | 
| 
       55 
     | 
    
         
            -
               * @defaultValue "100%"
         
     | 
| 
       56 
     | 
    
         
            -
               */
         
     | 
| 
       57 
     | 
    
         
            -
              width: FrameProps["width"];
         
     | 
| 
       58 
61 
     | 
    
         
             
            }
         
     | 
| 
       59 
62 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
            const  
     | 
| 
      
 63 
     | 
    
         
            +
            const defaultIFrameProps: FrameProps = {
         
     | 
| 
       61 
64 
     | 
    
         
             
              width: "100%",
         
     | 
| 
       62 
65 
     | 
    
         
             
              height: "100%",
         
     | 
| 
       63 
66 
     | 
    
         
             
              style: {
         
     | 
| 
         @@ -65,23 +68,26 @@ const defaultFrameProps: FrameProps = { 
     | 
|
| 
       65 
68 
     | 
    
         
             
              },
         
     | 
| 
       66 
69 
     | 
    
         
             
            };
         
     | 
| 
       67 
70 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
            const defaultSandbox = "allow-scripts";
         
     | 
| 
      
 71 
     | 
    
         
            +
            const defaultSandbox = "allow-scripts allow-forms allow-same-origin";
         
     | 
| 
       69 
72 
     | 
    
         | 
| 
       70 
73 
     | 
    
         
             
            /**
         
     | 
| 
       71 
74 
     | 
    
         
             
             * An iframe that attaches to a running GuestServer, to display visible UI pages
         
     | 
| 
       72 
75 
     | 
    
         
             
             * delivered by the Extension server.
         
     | 
| 
       73 
76 
     | 
    
         
             
             * @public
         
     | 
| 
       74 
77 
     | 
    
         
             
             */
         
     | 
| 
       75 
     | 
    
         
            -
            export  
     | 
| 
      
 78 
     | 
    
         
            +
            export const GuestUIFrame = ({
         
     | 
| 
       76 
79 
     | 
    
         
             
              guestId,
         
     | 
| 
       77 
80 
     | 
    
         
             
              src = "",
         
     | 
| 
       78 
81 
     | 
    
         
             
              onConnect,
         
     | 
| 
       79 
82 
     | 
    
         
             
              onDisconnect,
         
     | 
| 
       80 
83 
     | 
    
         
             
              onConnectionError,
         
     | 
| 
      
 84 
     | 
    
         
            +
              onResize,
         
     | 
| 
       81 
85 
     | 
    
         
             
              methods,
         
     | 
| 
       82 
86 
     | 
    
         
             
              sandbox = "",
         
     | 
| 
       83 
     | 
    
         
            -
               
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
      
 87 
     | 
    
         
            +
              style,
         
     | 
| 
      
 88 
     | 
    
         
            +
              ...customIFrameProps
         
     | 
| 
      
 89 
     | 
    
         
            +
            }: GuestUIProps) => {
         
     | 
| 
      
 90 
     | 
    
         
            +
              const ref = useRef<HTMLIFrameElement>();
         
     | 
| 
       85 
91 
     | 
    
         
             
              const { host } = useHost();
         
     | 
| 
       86 
92 
     | 
    
         
             
              if (!host) {
         
     | 
| 
       87 
93 
     | 
    
         
             
                return null;
         
     | 
| 
         @@ -89,39 +95,66 @@ export function GuestUIFrame({ 
     | 
|
| 
       89 
95 
     | 
    
         
             
              const guest = host.guests.get(guestId);
         
     | 
| 
       90 
96 
     | 
    
         
             
              const frameUrl = new URL(src, guest.url.href);
         
     | 
| 
       91 
97 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
               
     | 
| 
       93 
     | 
    
         
            -
                if ( 
     | 
| 
      
 98 
     | 
    
         
            +
              useEffect(() => {
         
     | 
| 
      
 99 
     | 
    
         
            +
                if (ref.current) {
         
     | 
| 
      
 100 
     | 
    
         
            +
                  let mounted = true;
         
     | 
| 
      
 101 
     | 
    
         
            +
                  let connection: CrossRealmObject<VirtualApi>;
         
     | 
| 
      
 102 
     | 
    
         
            +
                  const connectionFrame = ref.current;
         
     | 
| 
       94 
103 
     | 
    
         
             
                  if (methods) {
         
     | 
| 
       95 
104 
     | 
    
         
             
                    guest.provide(methods);
         
     | 
| 
       96 
105 
     | 
    
         
             
                  }
         
     | 
| 
       97 
     | 
    
         
            -
                  const  
     | 
| 
       98 
     | 
    
         
            -
                   
     | 
| 
       99 
     | 
    
         
            -
                    .then(() => {
         
     | 
| 
       100 
     | 
    
         
            -
                       
     | 
| 
      
 106 
     | 
    
         
            +
                  const connecting = guest.attachUI(connectionFrame);
         
     | 
| 
      
 107 
     | 
    
         
            +
                  connecting
         
     | 
| 
      
 108 
     | 
    
         
            +
                    .then((c) => {
         
     | 
| 
      
 109 
     | 
    
         
            +
                      connection = c;
         
     | 
| 
      
 110 
     | 
    
         
            +
                      if (!mounted) {
         
     | 
| 
      
 111 
     | 
    
         
            +
                        c.tunnel.destroy();
         
     | 
| 
      
 112 
     | 
    
         
            +
                      } else if (onConnect) {
         
     | 
| 
       101 
113 
     | 
    
         
             
                        onConnect();
         
     | 
| 
       102 
114 
     | 
    
         
             
                      }
         
     | 
| 
       103 
115 
     | 
    
         
             
                    })
         
     | 
| 
       104 
116 
     | 
    
         
             
                    .catch((error: Error) => {
         
     | 
| 
       105 
     | 
    
         
            -
                      if ( 
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
      
 117 
     | 
    
         
            +
                      if (mounted && !connection && connectionFrame === ref.current) {
         
     | 
| 
      
 118 
     | 
    
         
            +
                        const frameError = new Error(
         
     | 
| 
      
 119 
     | 
    
         
            +
                          `GuestUIFrame connection failed: ${
         
     | 
| 
      
 120 
     | 
    
         
            +
                            (error && error.stack) || error
         
     | 
| 
      
 121 
     | 
    
         
            +
                          }`
         
     | 
| 
      
 122 
     | 
    
         
            +
                        );
         
     | 
| 
      
 123 
     | 
    
         
            +
                        Object.assign(frameError, {
         
     | 
| 
      
 124 
     | 
    
         
            +
                          original: error,
         
     | 
| 
      
 125 
     | 
    
         
            +
                          ref,
         
     | 
| 
      
 126 
     | 
    
         
            +
                          guest,
         
     | 
| 
      
 127 
     | 
    
         
            +
                          host,
         
     | 
| 
      
 128 
     | 
    
         
            +
                        });
         
     | 
| 
      
 129 
     | 
    
         
            +
                        if (onConnectionError) onConnectionError(frameError);
         
     | 
| 
      
 130 
     | 
    
         
            +
                      }
         
     | 
| 
       107 
131 
     | 
    
         
             
                    });
         
     | 
| 
       108 
     | 
    
         
            -
                  return  
     | 
| 
       109 
     | 
    
         
            -
                     
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                       
     | 
| 
      
 132 
     | 
    
         
            +
                  return () => {
         
     | 
| 
      
 133 
     | 
    
         
            +
                    mounted = false;
         
     | 
| 
      
 134 
     | 
    
         
            +
                    if (connection) {
         
     | 
| 
      
 135 
     | 
    
         
            +
                      connection.tunnel.destroy();
         
     | 
| 
       112 
136 
     | 
    
         
             
                    }
         
     | 
| 
       113 
137 
     | 
    
         
             
                  };
         
     | 
| 
       114 
138 
     | 
    
         
             
                }
         
     | 
| 
       115 
139 
     | 
    
         
             
              }, []);
         
     | 
| 
       116 
140 
     | 
    
         | 
| 
       117 
     | 
    
         
            -
               
     | 
| 
       118 
     | 
    
         
            -
                 
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
      
 141 
     | 
    
         
            +
              useEffect(() => {
         
     | 
| 
      
 142 
     | 
    
         
            +
                if (ref.current && onResize) {
         
     | 
| 
      
 143 
     | 
    
         
            +
                  const currentFrame = ref.current;
         
     | 
| 
      
 144 
     | 
    
         
            +
                  return guest.addEventListener(
         
     | 
| 
      
 145 
     | 
    
         
            +
                    "guestresize",
         
     | 
| 
      
 146 
     | 
    
         
            +
                    ({ detail: { guestPort, iframe, dimensions } }) => {
         
     | 
| 
      
 147 
     | 
    
         
            +
                      if (guestPort.id === guest.id && iframe === currentFrame) {
         
     | 
| 
      
 148 
     | 
    
         
            +
                        onResize(dimensions);
         
     | 
| 
      
 149 
     | 
    
         
            +
                      }
         
     | 
| 
      
 150 
     | 
    
         
            +
                    }
         
     | 
| 
      
 151 
     | 
    
         
            +
                  );
         
     | 
| 
      
 152 
     | 
    
         
            +
                }
         
     | 
| 
      
 153 
     | 
    
         
            +
              }, [ref.current, guest.id, onResize]);
         
     | 
| 
       122 
154 
     | 
    
         | 
| 
       123 
155 
     | 
    
         
             
              return (
         
     | 
| 
       124 
156 
     | 
    
         
             
                <iframe
         
     | 
| 
      
 157 
     | 
    
         
            +
                  {...defaultIFrameProps}
         
     | 
| 
       125 
158 
     | 
    
         
             
                  ref={ref}
         
     | 
| 
       126 
159 
     | 
    
         
             
                  src={frameUrl.href}
         
     | 
| 
       127 
160 
     | 
    
         
             
                  name={`uix-guest-${guest.id}`}
         
     | 
| 
         @@ -130,8 +163,14 @@ export function GuestUIFrame({ 
     | 
|
| 
       130 
163 
     | 
    
         
             
                      ? makeSandboxAttrs(defaultSandbox, sandbox).join(" ")
         
     | 
| 
       131 
164 
     | 
    
         
             
                      : defaultSandbox
         
     | 
| 
       132 
165 
     | 
    
         
             
                  }
         
     | 
| 
       133 
     | 
    
         
            -
                  { 
     | 
| 
      
 166 
     | 
    
         
            +
                  style={
         
     | 
| 
      
 167 
     | 
    
         
            +
                    style
         
     | 
| 
      
 168 
     | 
    
         
            +
                      ? { ...style, ...defaultIFrameProps.style }
         
     | 
| 
      
 169 
     | 
    
         
            +
                      : defaultIFrameProps.style
         
     | 
| 
      
 170 
     | 
    
         
            +
                  }
         
     | 
| 
      
 171 
     | 
    
         
            +
                  {...customIFrameProps}
         
     | 
| 
      
 172 
     | 
    
         
            +
                  {...requiredIframeProps}
         
     | 
| 
       134 
173 
     | 
    
         
             
                />
         
     | 
| 
       135 
174 
     | 
    
         
             
              );
         
     | 
| 
       136 
     | 
    
         
            -
            }
         
     | 
| 
      
 175 
     | 
    
         
            +
            };
         
     | 
| 
       137 
176 
     | 
    
         
             
            export default GuestUIFrame;
         
     | 
    
        package/src/extension-context.ts
    CHANGED