@persona/layout-editor-remote-module 0.8.1 → 0.9.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.
@@ -1,5 +1,5 @@
1
1
  import { n as Json, t as RemoteModuleContext } from "./protocol-Dqnl8JTs.mjs";
2
- import { CSSProperties, ReactNode } from "react";
2
+ import { CSSProperties, ReactNode, Ref } from "react";
3
3
 
4
4
  //#region src/bridge/host/buildModuleSrc.d.ts
5
5
  type BuildModuleSrcOptions = {
@@ -30,6 +30,8 @@ type RemoteModuleFrameProps = {
30
30
  minHeight?: number;
31
31
  className?: string;
32
32
  style?: CSSProperties;
33
+ /** Receives the underlying <iframe> so a host can attach extra postMessage bridges. */
34
+ iframeRef?: Ref<HTMLIFrameElement>;
33
35
  data: Json;
34
36
  context: RemoteModuleContext;
35
37
  resolveDataPath: ResolveDataPath;
@@ -52,6 +54,7 @@ declare function RemoteModuleFrame({
52
54
  minHeight,
53
55
  className,
54
56
  style,
57
+ iframeRef: externalIframeRef,
55
58
  data,
56
59
  context,
57
60
  resolveDataPath,
@@ -1,5 +1,5 @@
1
1
  import { a as assertNotSelfOrigin, i as parseModuleToHostMessage, n as SOURCE, t as PROTOCOL_VERSION } from "./protocol-D_pdVZjs.mjs";
2
- import { useEffect, useMemo, useRef, useState } from "react";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
 
5
5
  //#region src/bridge/host/buildModuleSrc.ts
@@ -145,14 +145,27 @@ function withDynamicHeight(context, dynamicHeight) {
145
145
  dynamicHeight
146
146
  };
147
147
  }
148
- function RemoteModuleFrame({ documentUrl, moduleOrigin, accessToken, environmentId, locale, extraParams, title, sandbox, referrerPolicy = "no-referrer", initRetryMs, initRetryTimeoutMs, dynamicHeight = false, heightOffset = 0, minHeight, className, style, data, context, resolveDataPath, onRenderError }) {
148
+ function RemoteModuleFrame({ documentUrl, moduleOrigin, accessToken, environmentId, locale, extraParams, title, sandbox, referrerPolicy = "no-referrer", initRetryMs, initRetryTimeoutMs, dynamicHeight = false, heightOffset = 0, minHeight, className, style, iframeRef: externalIframeRef, data, context, resolveDataPath, onRenderError }) {
149
149
  const iframeRef = useRef(null);
150
150
  const dataRef = useRef(data);
151
151
  const contextRef = useRef(withDynamicHeight(context, dynamicHeight));
152
152
  const onRenderErrorRef = useRef(onRenderError);
153
153
  const resolveDataPathRef = useRef(resolveDataPath);
154
154
  const bridgeRef = useRef(void 0);
155
+ const externalCleanupRef = useRef(void 0);
155
156
  const [height, setHeight] = useState();
157
+ const setRefs = useCallback((node) => {
158
+ iframeRef.current = node;
159
+ if (typeof externalIframeRef === "function") if (node) {
160
+ const cleanup = externalIframeRef(node);
161
+ externalCleanupRef.current = typeof cleanup === "function" ? cleanup : void 0;
162
+ } else if (externalCleanupRef.current) {
163
+ const cleanup = externalCleanupRef.current;
164
+ externalCleanupRef.current = void 0;
165
+ cleanup();
166
+ } else externalIframeRef(null);
167
+ else if (externalIframeRef) externalIframeRef.current = node;
168
+ }, [externalIframeRef]);
156
169
  const hostContext = useMemo(() => withDynamicHeight(context, dynamicHeight), [context, dynamicHeight]);
157
170
  dataRef.current = data;
158
171
  contextRef.current = hostContext;
@@ -205,7 +218,7 @@ function RemoteModuleFrame({ documentUrl, moduleOrigin, accessToken, environment
205
218
  }, [hostContext]);
206
219
  const computedHeight = dynamicHeight && height !== void 0 ? `${Math.max(height + heightOffset, minHeight ?? 0)}px` : minHeight === void 0 ? "100%" : `${minHeight}px`;
207
220
  return /* @__PURE__ */ jsx("iframe", {
208
- ref: iframeRef,
221
+ ref: setRefs,
209
222
  src,
210
223
  title,
211
224
  sandbox,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@persona/layout-editor-remote-module",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Shared manifest format, Vite plugin, and host/iframe bridge for remotely-defined dashboard layout modules in Persona dashboard apps.",
5
5
  "license": "SEE LICENSE",
6
6
  "type": "module",