@machinemetrics/mm-react-embeddable 0.9.5 → 0.9.7

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,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),l=require("prop-types"),I=require("styled-components"),p=e.createContext(null),M=({children:n})=>{const[c,i]=e.useState({}),t=e.useRef({}),f=e.useCallback((s,r,a)=>{i(o=>({...o,[s]:{origin:r,frameRef:a}}))},[]);e.useEffect(()=>{const s=r=>{var o,m;if(!((o=r==null?void 0:r.data)!=null&&o.instanceId))return;(((m=t.current[r.data.instanceId])==null?void 0:m[r.data.type])||[]).forEach(E=>E(r.data))};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[c]);const u=e.useCallback((s,r,a)=>{const o=c[s];if(!o){console.warn(`Origin not set for id: ${s}. Unable to send message.`);return}o.frameRef.current.contentWindow.postMessage({type:r,...a,instanceId:s},o.origin)},[c]),d={registerFrame:f,sendMessage:u,addListener:(s,r,a)=>(t.current[s]||(t.current[s]={}),t.current[s][r]||(t.current[s][r]=[]),t.current[s][r].push(a),()=>{t.current[s][r]=t.current[s][r].filter(o=>o!==a)})};return e.createElement(p.Provider,{value:d},n)},y=(n,c,i)=>{const t=e.useContext(p);if(t===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const f=e.useRef(i);return e.useEffect(()=>{f.current=i},[i]),e.useEffect(()=>{if(!(!n||!c))return t.addListener(n,c,(...u)=>f.current(...u))},[t,n,c]),e.useCallback((u,d)=>t.sendMessage(n,u,d),[t,n])};M.propTypes={children:l.node.isRequired};const P=I.iframe`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),l=require("prop-types"),P=require("styled-components"),p=e.createContext(null),M=({children:n})=>{const[c,i]=e.useState({}),t=e.useRef({}),f=e.useCallback((s,r,a)=>{i(o=>({...o,[s]:{origin:r,frameRef:a}}))},[]);e.useEffect(()=>{const s=r=>{var o,m;if(!((o=r==null?void 0:r.data)!=null&&o.instanceId))return;(((m=t.current[r.data.instanceId])==null?void 0:m[r.data.type])||[]).forEach(E=>E(r.data))};return window.addEventListener("message",s),()=>{window.removeEventListener("message",s)}},[c]);const u=e.useCallback((s,r,a)=>{const o=c[s];if(!o){console.warn(`Origin not set for id: ${s}. Unable to send message.`);return}o.frameRef.current.contentWindow.postMessage({type:r,...a,instanceId:s},o.origin)},[c]),d={registerFrame:f,sendMessage:u,addListener:(s,r,a)=>(t.current[s]||(t.current[s]={}),t.current[s][r]||(t.current[s][r]=[]),t.current[s][r].push(a),()=>{t.current[s][r]=t.current[s][r].filter(o=>o!==a)})};return e.createElement(p.Provider,{value:d},n)},y=(n,c,i)=>{const t=e.useContext(p);if(t===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const f=e.useRef(i);return e.useEffect(()=>{f.current=i},[i]),e.useEffect(()=>{if(!(!n||!c))return t.addListener(n,c,(...u)=>f.current(...u))},[t,n,c]),e.useCallback((u,d)=>t.sendMessage(n,u,d),[t,n])};M.propTypes={children:l.node.isRequired};const x=P.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
5
  visibility: ${n=>n.isready?"visible":"hidden"};
6
- `,h=({id:n,genericFrameFallback:c,src:i,path:t,onInit:f=()=>{},...u})=>{const d=e.useRef(),[s,r]=e.useState(),[a,o]=e.useState(0),{registerFrame:m,sendMessage:E}=e.useContext(MMEmbeddedWrapperContext),[g,w]=e.useState(),[R,C]=e.useState(!1);return e.useEffect(()=>{t!==void 0&&(console.log(t),w(t))},[t]),e.useEffect(()=>{g===void 0||!a||E(n,"navigate",{path:g})},[g,a,n,E]),e.useEffect(()=>{!i||!n||!d||(async()=>{const b=new URL(i);m(n,b.origin,d),f();try{if((await(await fetch(`${b.origin}/mm-app-manifest.json`)).json()).manifestVersion)r(`${b.origin}/mm-embedded-interop?id=${n}`);else throw Error()}catch{c?(r(i),o(1)):C(!0)}})()},[i,n,m,d]),y(n,"ready",()=>o(b=>b+1)),R?e.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded.")):e.createElement(P,{isready:a,ref:d,src:s,...u})};h.propTypes={id:l.string,genericFrameFallback:l.bool,src:l.string.isRequired,path:l.string,onInit:l.func};exports.MMEmbeddableZone=h;exports.MMEmbeddableZoneProvider=M;exports.useEmbeddedEffect=y;
6
+ `,h=({id:n,genericFrameFallback:c,src:i,path:t,onInit:f=()=>{},...u})=>{const d=e.useRef(),[s,r]=e.useState(),[a,o]=e.useState(0),{registerFrame:m,sendMessage:E}=e.useContext(p),[g,w]=e.useState(),[R,C]=e.useState(!1);return e.useEffect(()=>{t!==void 0&&(console.log(t),w(t))},[t]),e.useEffect(()=>{g===void 0||!a||E(n,"navigate",{path:g})},[g,a,n,E]),e.useEffect(()=>{!i||!n||!d||(async()=>{const b=new URL(i);m(n,b.origin,d),f();try{if((await(await fetch(`${b.origin}/mm-app-manifest.json`)).json()).manifestVersion)r(`${b.origin}/mm-embedded-interop?id=${n}`);else throw Error()}catch{c?(r(i),o(1)):C(!0)}})()},[i,n,m,d]),y(n,"ready",()=>o(b=>b+1)),R?e.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded.")):e.createElement(x,{isready:a,ref:d,src:s,...u})};h.propTypes={id:l.string,genericFrameFallback:l.bool,src:l.string.isRequired,path:l.string,onInit:l.func};exports.MMEmbeddableZone=h;exports.MMEmbeddableZoneProvider=M;exports.useEmbeddedEffect=y;
@@ -1,7 +1,7 @@
1
- import E, { createContext as F, useState as b, useRef as M, useCallback as y, useEffect as l, useContext as w } from "react";
1
+ import E, { createContext as P, useState as b, useRef as M, useCallback as y, useEffect as l, useContext as R } from "react";
2
2
  import f from "prop-types";
3
- import P from "styled-components";
4
- const R = F(null), $ = ({ children: n }) => {
3
+ import C from "styled-components";
4
+ const w = P(null), $ = ({ children: n }) => {
5
5
  const [a, i] = b({}), e = M({}), u = y((r, t, o) => {
6
6
  i((s) => ({ ...s, [r]: { origin: t, frameRef: o } }));
7
7
  }, []);
@@ -10,7 +10,7 @@ const R = F(null), $ = ({ children: n }) => {
10
10
  var s, m;
11
11
  if (!((s = t == null ? void 0 : t.data) != null && s.instanceId))
12
12
  return;
13
- (((m = e.current[t.data.instanceId]) == null ? void 0 : m[t.data.type]) || []).forEach((g) => g(t.data));
13
+ (((m = e.current[t.data.instanceId]) == null ? void 0 : m[t.data.type]) || []).forEach((p) => p(t.data));
14
14
  };
15
15
  return window.addEventListener("message", r), () => {
16
16
  window.removeEventListener("message", r);
@@ -36,9 +36,9 @@ const R = F(null), $ = ({ children: n }) => {
36
36
  e.current[r][t] = e.current[r][t].filter((s) => s !== o);
37
37
  })
38
38
  };
39
- return /* @__PURE__ */ E.createElement(R.Provider, { value: c }, n);
39
+ return /* @__PURE__ */ E.createElement(w.Provider, { value: c }, n);
40
40
  }, Z = (n, a, i) => {
41
- const e = w(R);
41
+ const e = R(w);
42
42
  if (e === null)
43
43
  throw new Error(
44
44
  "useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
@@ -61,7 +61,7 @@ const R = F(null), $ = ({ children: n }) => {
61
61
  $.propTypes = {
62
62
  children: f.node.isRequired
63
63
  };
64
- const j = P.iframe`
64
+ const j = C.iframe`
65
65
  width: 100%;
66
66
  height: 100%;
67
67
  border: none;
@@ -75,25 +75,25 @@ const j = P.iframe`
75
75
  },
76
76
  ...d
77
77
  }) => {
78
- const c = M(), [r, t] = b(), [o, s] = b(0), { registerFrame: m, sendMessage: g } = w(MMEmbeddedWrapperContext), [h, x] = b(), [I, L] = b(!1);
78
+ const c = M(), [r, t] = b(), [o, s] = b(0), { registerFrame: m, sendMessage: p } = R(w), [h, I] = b(), [x, L] = b(!1);
79
79
  return l(() => {
80
- e !== void 0 && (console.log(e), x(e));
80
+ e !== void 0 && (console.log(e), I(e));
81
81
  }, [e]), l(() => {
82
- h === void 0 || !o || g(n, "navigate", { path: h });
83
- }, [h, o, n, g]), l(() => {
82
+ h === void 0 || !o || p(n, "navigate", { path: h });
83
+ }, [h, o, n, p]), l(() => {
84
84
  !i || !n || !c || (async () => {
85
- const p = new URL(i);
86
- m(n, p.origin, c), u();
85
+ const g = new URL(i);
86
+ m(n, g.origin, c), u();
87
87
  try {
88
- if ((await (await fetch(`${p.origin}/mm-app-manifest.json`)).json()).manifestVersion)
89
- t(`${p.origin}/mm-embedded-interop?id=${n}`);
88
+ if ((await (await fetch(`${g.origin}/mm-app-manifest.json`)).json()).manifestVersion)
89
+ t(`${g.origin}/mm-embedded-interop?id=${n}`);
90
90
  else
91
91
  throw Error();
92
92
  } catch {
93
93
  a ? (t(i), s(1)) : L(!0);
94
94
  }
95
95
  })();
96
- }, [i, n, m, c]), Z(n, "ready", () => s((p) => p + 1)), I ? /* @__PURE__ */ E.createElement(
96
+ }, [i, n, m, c]), Z(n, "ready", () => s((g) => g + 1)), x ? /* @__PURE__ */ E.createElement(
97
97
  "div",
98
98
  {
99
99
  style: {
@@ -1,6 +1,6 @@
1
- (function(i,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i["mm-react-embeddable"]={},i.React,i.PropTypes,i.styled))})(this,function(i,e,l,C){"use strict";const M=e.createContext(null),h=({children:s})=>{const[f,u]=e.useState({}),t=e.useRef({}),m=e.useCallback((r,n,d)=>{u(o=>({...o,[r]:{origin:n,frameRef:d}}))},[]);e.useEffect(()=>{const r=n=>{var o,b;if(!((o=n==null?void 0:n.data)!=null&&o.instanceId))return;(((b=t.current[n.data.instanceId])==null?void 0:b[n.data.type])||[]).forEach(p=>p(n.data))};return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},[f]);const c=e.useCallback((r,n,d)=>{const o=f[r];if(!o){console.warn(`Origin not set for id: ${r}. Unable to send message.`);return}o.frameRef.current.contentWindow.postMessage({type:n,...d,instanceId:r},o.origin)},[f]),a={registerFrame:m,sendMessage:c,addListener:(r,n,d)=>(t.current[r]||(t.current[r]={}),t.current[r][n]||(t.current[r][n]=[]),t.current[r][n].push(d),()=>{t.current[r][n]=t.current[r][n].filter(o=>o!==d)})};return e.createElement(M.Provider,{value:a},s)},y=(s,f,u)=>{const t=e.useContext(M);if(t===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=e.useRef(u);return e.useEffect(()=>{m.current=u},[u]),e.useEffect(()=>{if(!(!s||!f))return t.addListener(s,f,(...c)=>m.current(...c))},[t,s,f]),e.useCallback((c,a)=>t.sendMessage(s,c,a),[t,s])};h.propTypes={children:l.node.isRequired};const x=C.iframe`
1
+ (function(i,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("prop-types"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","prop-types","styled-components"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i["mm-react-embeddable"]={},i.React,i.PropTypes,i.styled))})(this,function(i,e,l,C){"use strict";const p=e.createContext(null),y=({children:s})=>{const[f,u]=e.useState({}),t=e.useRef({}),m=e.useCallback((r,n,d)=>{u(o=>({...o,[r]:{origin:n,frameRef:d}}))},[]);e.useEffect(()=>{const r=n=>{var o,b;if(!((o=n==null?void 0:n.data)!=null&&o.instanceId))return;(((b=t.current[n.data.instanceId])==null?void 0:b[n.data.type])||[]).forEach(g=>g(n.data))};return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},[f]);const c=e.useCallback((r,n,d)=>{const o=f[r];if(!o){console.warn(`Origin not set for id: ${r}. Unable to send message.`);return}o.frameRef.current.contentWindow.postMessage({type:n,...d,instanceId:r},o.origin)},[f]),a={registerFrame:m,sendMessage:c,addListener:(r,n,d)=>(t.current[r]||(t.current[r]={}),t.current[r][n]||(t.current[r][n]=[]),t.current[r][n].push(d),()=>{t.current[r][n]=t.current[r][n].filter(o=>o!==d)})};return e.createElement(p.Provider,{value:a},s)},M=(s,f,u)=>{const t=e.useContext(p);if(t===null)throw new Error("useEmbeddedEffect must be used within a MMEmbeddableZoneProvider");const m=e.useRef(u);return e.useEffect(()=>{m.current=u},[u]),e.useEffect(()=>{if(!(!s||!f))return t.addListener(s,f,(...c)=>m.current(...c))},[t,s,f]),e.useCallback((c,a)=>t.sendMessage(s,c,a),[t,s])};y.propTypes={children:l.node.isRequired};const I=C.iframe`
2
2
  width: 100%;
3
3
  height: 100%;
4
4
  border: none;
5
5
  visibility: ${s=>s.isready?"visible":"hidden"};
6
- `,w=({id:s,genericFrameFallback:f,src:u,path:t,onInit:m=()=>{},...c})=>{const a=e.useRef(),[r,n]=e.useState(),[d,o]=e.useState(0),{registerFrame:b,sendMessage:p}=e.useContext(MMEmbeddedWrapperContext),[g,I]=e.useState(),[L,S]=e.useState(!1);return e.useEffect(()=>{t!==void 0&&(console.log(t),I(t))},[t]),e.useEffect(()=>{g===void 0||!d||p(s,"navigate",{path:g})},[g,d,s,p]),e.useEffect(()=>{!u||!s||!a||(async()=>{const E=new URL(u);b(s,E.origin,a),m();try{if((await(await fetch(`${E.origin}/mm-app-manifest.json`)).json()).manifestVersion)n(`${E.origin}/mm-embedded-interop?id=${s}`);else throw Error()}catch{f?(n(u),o(1)):S(!0)}})()},[u,s,b,a]),y(s,"ready",()=>o(E=>E+1)),L?e.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded.")):e.createElement(x,{isready:d,ref:a,src:r,...c})};w.propTypes={id:l.string,genericFrameFallback:l.bool,src:l.string.isRequired,path:l.string,onInit:l.func},i.MMEmbeddableZone=w,i.MMEmbeddableZoneProvider=h,i.useEmbeddedEffect=y,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
6
+ `,w=({id:s,genericFrameFallback:f,src:u,path:t,onInit:m=()=>{},...c})=>{const a=e.useRef(),[r,n]=e.useState(),[d,o]=e.useState(0),{registerFrame:b,sendMessage:g}=e.useContext(p),[h,x]=e.useState(),[L,S]=e.useState(!1);return e.useEffect(()=>{t!==void 0&&(console.log(t),x(t))},[t]),e.useEffect(()=>{h===void 0||!d||g(s,"navigate",{path:h})},[h,d,s,g]),e.useEffect(()=>{!u||!s||!a||(async()=>{const E=new URL(u);b(s,E.origin,a),m();try{if((await(await fetch(`${E.origin}/mm-app-manifest.json`)).json()).manifestVersion)n(`${E.origin}/mm-embedded-interop?id=${s}`);else throw Error()}catch{f?(n(u),o(1)):S(!0)}})()},[u,s,b,a]),M(s,"ready",()=>o(E=>E+1)),L?e.createElement("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("div",{style:{textAlign:"center"}},"Application must adhere to the MM App Manifest specification to be embedded.")):e.createElement(I,{isready:d,ref:a,src:r,...c})};w.propTypes={id:l.string,genericFrameFallback:l.bool,src:l.string.isRequired,path:l.string,onInit:l.func},i.MMEmbeddableZone=w,i.MMEmbeddableZoneProvider=y,i.useEmbeddedEffect=M,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-react-embeddable",
3
- "version": "0.9.5",
3
+ "version": "0.9.7",
4
4
  "license": "MIT",
5
5
  "module": "dist/mm-react-embeddable.es.js",
6
6
  "main": "dist/mm-react-embeddable.cjs.js",
7
7
  "source": "src/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "imports": "./dist/mm-react-embeddable.es.js",
11
+ "require": "./dist/mm-react-embeddable.cjs.js"
12
+ }
13
+ },
8
14
  "type": "module",
9
15
  "engines": {
10
16
  "node": ">=18"