@machinemetrics/mm-react-embeddable 0.9.4 → 0.9.6

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"),h=e.createContext(null),p=({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(h.Provider,{value:d},n)},M=(n,c,i)=>{const t=e.useContext(h);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])};p.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
- `,y=({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,x]=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)):x(!0)}})()},[i,n,m,d]),M(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})};y.propTypes={id:l.string,genericFrameFallback:l.bool,src:l.string.isRequired,path:l.string,onInit:l.func};module.exports={MMEmbeddableZone:y,MMEmbeddableZoneProvider:p,useEmbeddedEffect:M};exports.MMEmbeddableZone=y;exports.MMEmbeddableZoneProvider=p;exports.useEmbeddedEffect=M;
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 Z, 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 j from "styled-components";
4
- const R = Z(null), x = ({ 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 = Z(null), x = ({ 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 = Z(null), x = ({ 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);
40
- }, I = (n, a, i) => {
41
- const e = w(R);
39
+ return /* @__PURE__ */ E.createElement(w.Provider, { value: c }, n);
40
+ }, Z = (n, a, i) => {
41
+ const e = R(w);
42
42
  if (e === null)
43
43
  throw new Error(
44
44
  "useEmbeddedEffect must be used within a MMEmbeddableZoneProvider"
@@ -58,15 +58,15 @@ const R = Z(null), x = ({ children: n }) => {
58
58
  [e, n]
59
59
  );
60
60
  };
61
- x.propTypes = {
61
+ $.propTypes = {
62
62
  children: f.node.isRequired
63
63
  };
64
- const v = j.iframe`
64
+ const j = C.iframe`
65
65
  width: 100%;
66
66
  height: 100%;
67
67
  border: none;
68
68
  visibility: ${(n) => n.isready ? "visible" : "hidden"};
69
- `, L = ({
69
+ `, v = ({
70
70
  id: n,
71
71
  genericFrameFallback: a,
72
72
  src: i,
@@ -75,25 +75,25 @@ const v = j.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, C] = b(), [F, P] = 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), C(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
- a ? (t(i), s(1)) : P(!0);
93
+ a ? (t(i), s(1)) : L(!0);
94
94
  }
95
95
  })();
96
- }, [i, n, m, c]), I(n, "ready", () => s((p) => p + 1)), F ? /* @__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: {
@@ -104,22 +104,17 @@ const v = j.iframe`
104
104
  }
105
105
  },
106
106
  /* @__PURE__ */ E.createElement("div", { style: { textAlign: "center" } }, "Application must adhere to the MM App Manifest specification to be embedded.")
107
- ) : /* @__PURE__ */ E.createElement(v, { isready: o, ref: c, src: r, ...d });
107
+ ) : /* @__PURE__ */ E.createElement(j, { isready: o, ref: c, src: r, ...d });
108
108
  };
109
- L.propTypes = {
109
+ v.propTypes = {
110
110
  id: f.string,
111
111
  genericFrameFallback: f.bool,
112
112
  src: f.string.isRequired,
113
113
  path: f.string,
114
114
  onInit: f.func
115
115
  };
116
- module.exports = {
117
- MMEmbeddableZone: L,
118
- MMEmbeddableZoneProvider: x,
119
- useEmbeddedEffect: I
120
- };
121
116
  export {
122
- L as MMEmbeddableZone,
123
- x as MMEmbeddableZoneProvider,
124
- I as useEmbeddedEffect
117
+ v as MMEmbeddableZone,
118
+ $ as MMEmbeddableZoneProvider,
119
+ Z as useEmbeddedEffect
125
120
  };
@@ -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,x){"use strict";const w=e.createContext(null),g=({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(w.Provider,{value:a},s)},M=(s,f,u)=>{const t=e.useContext(w);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])};g.propTypes={children:l.node.isRequired};const C=x.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
- `,h=({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),[y,I]=e.useState(),[L,S]=e.useState(!1);return e.useEffect(()=>{t!==void 0&&(console.log(t),I(t))},[t]),e.useEffect(()=>{y===void 0||!d||p(s,"navigate",{path:y})},[y,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]),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(C,{isready:d,ref:a,src:r,...c})};h.propTypes={id:l.string,genericFrameFallback:l.bool,src:l.string.isRequired,path:l.string,onInit:l.func},module.exports={MMEmbeddableZone:h,MMEmbeddableZoneProvider:g,useEmbeddedEffect:M},i.MMEmbeddableZone=h,i.MMEmbeddableZoneProvider=g,i.useEmbeddedEffect=M,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,14 @@
1
1
  {
2
2
  "name": "@machinemetrics/mm-react-embeddable",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
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
+ "imports": "./dist/mm-react-embeddable.es.js",
10
+ "require": "./dist/mm-react-embeddable.cjs.js"
11
+ },
8
12
  "type": "module",
9
13
  "engines": {
10
14
  "node": ">=18"