qureal-editor 1.0.8 → 1.0.9

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/index.es.js CHANGED
@@ -6,6 +6,21 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
6
6
  return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
7
7
  };
8
8
 
9
+ var defineProperty = function (obj, key, value) {
10
+ if (key in obj) {
11
+ Object.defineProperty(obj, key, {
12
+ value: value,
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true
16
+ });
17
+ } else {
18
+ obj[key] = value;
19
+ }
20
+
21
+ return obj;
22
+ };
23
+
9
24
  var _extends = Object.assign || function (target) {
10
25
  for (var i = 1; i < arguments.length; i++) {
11
26
  var source = arguments[i];
@@ -21,7 +36,11 @@ var _extends = Object.assign || function (target) {
21
36
  };
22
37
 
23
38
  function QurealiFrame(_ref) {
39
+ var _React$createElement;
40
+
24
41
  var slug = _ref.slug,
42
+ preview = _ref.preview,
43
+ query = _ref.query,
25
44
  _ref$type = _ref.type,
26
45
  type = _ref$type === undefined ? "creation" : _ref$type,
27
46
  _ref$style = _ref.style,
@@ -31,17 +50,15 @@ function QurealiFrame(_ref) {
31
50
  return React.createElement(
32
51
  Fragment,
33
52
  null,
34
- React.createElement("iframe", {
53
+ React.createElement("iframe", (_React$createElement = {
35
54
  id: "qureal_iframe",
36
55
  title: "Qureal"
37
56
  // src={`http://localhost:3201/embed/${creation_slug}`}
38
- , src: type === "creation" ? "https://show.qureal.com/embed/" + slug : "https://show.qureal.com/ts/" + slug
39
- // src={`https://show.qureal.com/embed/${slug}`}
40
- , style: _extends({
41
- width: "100%",
42
- height: "100vh"
43
- }, style)
44
- })
57
+ , src: type === "creation" ? "https://show.qureal.com/embed/" + slug + "?" + (preview ? "preview&" : "") + query : "https://show.qureal.com/ts/" + slug
58
+ }, defineProperty(_React$createElement, "src", type === "creation" ? "http://localhost:3201/embed/" + slug + "?" + (preview ? "preview&" : "") + query : "https://show.qureal.com/ts/" + slug), defineProperty(_React$createElement, "style", _extends({
59
+ width: "100%",
60
+ height: "100vh"
61
+ }, style)), _React$createElement))
45
62
  );
46
63
  }
47
64
 
@@ -55,6 +72,10 @@ var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
55
72
  function QurealViewer(_ref) {
56
73
  var _ref$slug = _ref.slug,
57
74
  slug = _ref$slug === undefined ? "qi_sample" : _ref$slug,
75
+ _ref$preview = _ref.preview,
76
+ preview = _ref$preview === undefined ? false : _ref$preview,
77
+ _ref$prefill = _ref.prefill,
78
+ prefill = _ref$prefill === undefined ? {} : _ref$prefill,
58
79
  _ref$type = _ref.type,
59
80
  type = _ref$type === undefined ? "creation" : _ref$type,
60
81
  _ref$onFormSubmit = _ref.onFormSubmit,
@@ -63,25 +84,36 @@ function QurealViewer(_ref) {
63
84
  style = _ref$style === undefined ? {} : _ref$style;
64
85
 
65
86
 
66
- var sendToIFrame = function sendToIFrame(creation_slug) {
87
+ var sendToIFrame = function sendToIFrame(msg) {
67
88
  console.log("Sending data to iFrame");
68
89
  var qureal_element = document.getElementById("qureal_iframe");
69
90
 
70
91
  var qureal_window = qureal_element ? qureal_element.contentWindow : null;
71
92
  if (qureal_window) {
72
- qureal_window.postMessage({
73
- message_type: "OPEN_CREATION",
74
- data: {
75
- slug: creation_slug
76
- }
77
- }, "*");
93
+ qureal_window.postMessage(msg, "*");
78
94
  console.log("Data sent to iframe");
79
95
  }
80
96
  };
81
97
 
82
98
  useEffect(function () {
83
- sendToIFrame(slug);
84
- }, [slug]);
99
+ sendToIFrame({
100
+ message_type: "OPEN_CREATION",
101
+ data: {
102
+ slug: slug,
103
+ preview: preview,
104
+ prefill: prefill
105
+ }
106
+ });
107
+ }, [slug, preview]);
108
+
109
+ useEffect(function () {
110
+ sendToIFrame({
111
+ message_type: "PREFILL",
112
+ data: {
113
+ prefill: prefill
114
+ }
115
+ });
116
+ }, [prefill]);
85
117
 
86
118
  useEffect(function () {
87
119
  var handler = function handler(ev) {
@@ -105,10 +137,28 @@ function QurealViewer(_ref) {
105
137
 
106
138
  return React.createElement(QurealiFrame$1, {
107
139
  slug: slug,
140
+ preview: preview,
141
+ query: queryfy(prefill),
108
142
  type: type,
109
143
  style: style
110
144
  });
111
145
  }
112
146
 
147
+ function queryfy(obj) {
148
+ var buildQuery = function buildQuery(prefix, obj) {
149
+ return Object.keys(obj).map(function (key) {
150
+ var value = obj[key];
151
+ var prefixedKey = prefix ? prefix + "." + key : key;
152
+ if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === 'object' && value !== null) {
153
+ return buildQuery(prefixedKey, value);
154
+ } else {
155
+ return prefixedKey + "=" + value;
156
+ }
157
+ }).join("&");
158
+ };
159
+
160
+ return buildQuery("", obj);
161
+ }
162
+
113
163
  export { QurealViewer };
114
164
  //# sourceMappingURL=index.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}` : `https://show.qureal.com/ts/${slug}`}\n // src={`https://show.qureal.com/embed/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {}\n}) {\n\n const sendToIFrame = (creation_slug) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: creation_slug\n }\n }, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame(slug)\n }, [slug])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n"],"names":["QurealiFrame","slug","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","onFormSubmit","sendToIFrame","creation_slug","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","handler","ev","includes","origin","babelHelpers.typeof","data","event_type","addEventListener","window","removeEventListener"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAGA,SAASA,YAAT,OAA+D;QAAvCC,IAAuC,QAAvCA,IAAuC;yBAAjCC,IAAiC;QAAjCA,IAAiC,6BAA1B,UAA0B;0BAAdC,KAAc;QAAdA,KAAc,8BAAN,EAAM;;;WAIvD;gBAAA;;;gBAEW,eADP;mBAEU;;cAEN,KAAKD,SAAS,UAAT,sCAAuDD,IAAvD,mCAA8FA;;cAEnG;uBACW,MADX;wBAEY;eACLE,KAHP;;KARZ;;;;AAmBJ,qBAAeC,MAAMC,IAAN,CAAWL,YAAX,EAAyB;WAAM,IAAN;CAAzB,CAAf;;ACtBA,IAAMM,kBAAkB,CAAC,yBAAD,EAA4B,uBAA5B,CAAxB;;AAEA,SAASC,YAAT,OAKG;yBAJCN,IAID;QAJCA,IAID,6BAJQ,WAIR;yBAHCC,IAGD;QAHCA,IAGD,6BAHQ,UAGR;iCAFCM,YAED;QAFCA,YAED,qCAFgB,YAAM,EAEtB;0BADCL,KACD;QADCA,KACD,8BADS,EACT;;;QAEOM,eAAe,SAAfA,YAAe,CAACC,aAAD,EAAmB;gBAC5BC,GAAR,CAAY,wBAAZ;YACMC,iBAAiBC,SAASC,cAAT,CAAwB,eAAxB,CAAvB;;YAEMC,gBAAgBH,iBAAiBA,eAAeI,aAAhC,GAAgD,IAAtE;YACID,aAAJ,EAAmB;0BACDE,WAAd,CAA0B;8BACR,eADQ;sBAEhB;0BACIP;;aAHd,EAKG,GALH;oBAMQC,GAAR,CAAY,qBAAZ;;KAZR;;cAgBU,YAAM;qBACCV,IAAb;KADJ,EAEG,CAACA,IAAD,CAFH;;cAIU,YAAM;YACNiB,UAAU,SAAVA,OAAU,CAACC,EAAD,EAAQ;gBAChBb,gBAAgBc,QAAhB,CAAyBD,GAAGE,MAA5B,KAAuCC,QAAOH,GAAGI,IAAV,MAAmB,QAA9D,EAAwE;wBAC5DJ,GAAGI,IAAH,CAAQC,UAAhB;yBACS,aAAL;qCACiBL,GAAGI,IAAH,CAAQA,IAArB;;;gCAGQZ,GAAR,CAAY,qBAAZ;gCACQA,GAAR,CAAYQ,GAAGI,IAAf;;;SARhB;;eAaOE,gBAAP,CAAwB,SAAxB,EAAmCP,OAAnC;eACO;mBAAMQ,OAAOC,mBAAP,CAA2B,SAA3B,EAAsCT,OAAtC,CAAN;SAAP;KAfJ,EAgBG,EAhBH;;WAmBI,oBAAClB,cAAD;cACUC,IADV;cAEUC,IAFV;eAGWC;MAJf;;;;;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, preview, query, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n src={type === \"creation\" ? `http://localhost:3201/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n preview = false,\n prefill = {},\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {}\n}) {\n\n const sendToIFrame = (msg) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage(msg, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: slug,\n preview: preview,\n prefill: prefill\n }\n })\n }, [slug, preview])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"PREFILL\",\n data: {\n prefill: prefill\n }\n })\n }, [prefill])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n preview={preview}\n query={queryfy(prefill)}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n\n\nfunction queryfy(obj) {\n const buildQuery = (prefix, obj) => {\n return Object.keys(obj)\n .map(key => {\n const value = obj[key];\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'object' && value !== null) {\n return buildQuery(prefixedKey, value);\n } else {\n return `${prefixedKey}=${value}`;\n }\n })\n .join(\"&\");\n };\n\n return buildQuery(\"\", obj);\n}"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","handler","ev","includes","origin","babelHelpers.typeof","data","event_type","addEventListener","window","removeEventListener","queryfy","obj","buildQuery","prefix","Object","keys","map","value","key","prefixedKey","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAASA,YAAT,OAA+E;;;QAAvDC,IAAuD,QAAvDA,IAAuD;QAAjDC,OAAiD,QAAjDA,OAAiD;QAAxCC,KAAwC,QAAxCA,KAAwC;yBAAjCC,IAAiC;QAAjCA,IAAiC,6BAA1B,UAA0B;0BAAdC,KAAc;QAAdA,KAAc,8BAAN,EAAM;;;WAIvE;gBAAA;;;gBAEW,eADP;mBAEU;;cAEN,KAAKD,SAAS,UAAT,sCAAuDH,IAAvD,UAA+DC,UAAU,UAAV,GAAuB,EAAtF,IAA2FC,KAA3F,mCAAmIF;uDACnIG,SAAS,UAAT,oCAAqDH,IAArD,UAA6DC,UAAU,UAAV,GAAuB,EAApF,IAAyFC,KAAzF,mCAAiIF,IAL1I;mBAOe,MAPf;oBAQgB;WACLI,KATX;KAFR;;;;AAmBJ,qBAAeC,MAAMC,IAAN,CAAWP,YAAX,EAAyB;WAAM,IAAN;CAAzB,CAAf;;ACtBA,IAAMQ,kBAAkB,CAAC,yBAAD,EAA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oBAACrB,cAAD;cACUC,IADV;iBAEaC,OAFb;eAGW6B,QAAQrB,OAAR,CAHX;cAIUN,IAJV;eAKWC;MANf;;;AAeJ,SAAS0B,OAAT,CAAiBC,GAAjB,EAAsB;QACZC,aAAa,SAAbA,UAAa,CAACC,MAAD,EAASF,GAAT,EAAiB;eACzBG,OAAOC,IAAP,CAAYJ,GAAZ,EACFK,GADE,CACE,eAAO;gBACFC,QAAQN,IAAIO,GAAJ,CAAd;gBACMC,cAAcN,SAAYA,MAAZ,SAAsBK,GAAtB,GAA8BA,GAAlD;gBACI,QAAOD,KAAP,yCAAOA,KAAP,OAAiB,QAAjB,IAA6BA,UAAU,IAA3C,EAAiD;uBACtCL,WAAWO,WAAX,EAAwBF,KAAxB,CAAP;aADJ,MAEO;uBACOE,WAAV,SAAyBF,KAAzB;;SAPL,EAUFG,IAVE,CAUG,GAVH,CAAP;KADJ;;WAcOR,WAAW,EAAX,EAAeD,GAAf,CAAP;;;;;"}
package/dist/index.js CHANGED
@@ -13,6 +13,21 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
13
13
  return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
14
14
  };
15
15
 
16
+ var defineProperty = function (obj, key, value) {
17
+ if (key in obj) {
18
+ Object.defineProperty(obj, key, {
19
+ value: value,
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true
23
+ });
24
+ } else {
25
+ obj[key] = value;
26
+ }
27
+
28
+ return obj;
29
+ };
30
+
16
31
  var _extends = Object.assign || function (target) {
17
32
  for (var i = 1; i < arguments.length; i++) {
18
33
  var source = arguments[i];
@@ -28,7 +43,11 @@ var _extends = Object.assign || function (target) {
28
43
  };
29
44
 
30
45
  function QurealiFrame(_ref) {
46
+ var _React$createElement;
47
+
31
48
  var slug = _ref.slug,
49
+ preview = _ref.preview,
50
+ query = _ref.query,
32
51
  _ref$type = _ref.type,
33
52
  type = _ref$type === undefined ? "creation" : _ref$type,
34
53
  _ref$style = _ref.style,
@@ -38,17 +57,15 @@ function QurealiFrame(_ref) {
38
57
  return React__default.createElement(
39
58
  React.Fragment,
40
59
  null,
41
- React__default.createElement("iframe", {
60
+ React__default.createElement("iframe", (_React$createElement = {
42
61
  id: "qureal_iframe",
43
62
  title: "Qureal"
44
63
  // src={`http://localhost:3201/embed/${creation_slug}`}
45
- , src: type === "creation" ? "https://show.qureal.com/embed/" + slug : "https://show.qureal.com/ts/" + slug
46
- // src={`https://show.qureal.com/embed/${slug}`}
47
- , style: _extends({
48
- width: "100%",
49
- height: "100vh"
50
- }, style)
51
- })
64
+ , src: type === "creation" ? "https://show.qureal.com/embed/" + slug + "?" + (preview ? "preview&" : "") + query : "https://show.qureal.com/ts/" + slug
65
+ }, defineProperty(_React$createElement, "src", type === "creation" ? "http://localhost:3201/embed/" + slug + "?" + (preview ? "preview&" : "") + query : "https://show.qureal.com/ts/" + slug), defineProperty(_React$createElement, "style", _extends({
66
+ width: "100%",
67
+ height: "100vh"
68
+ }, style)), _React$createElement))
52
69
  );
53
70
  }
54
71
 
@@ -62,6 +79,10 @@ var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
62
79
  function QurealViewer(_ref) {
63
80
  var _ref$slug = _ref.slug,
64
81
  slug = _ref$slug === undefined ? "qi_sample" : _ref$slug,
82
+ _ref$preview = _ref.preview,
83
+ preview = _ref$preview === undefined ? false : _ref$preview,
84
+ _ref$prefill = _ref.prefill,
85
+ prefill = _ref$prefill === undefined ? {} : _ref$prefill,
65
86
  _ref$type = _ref.type,
66
87
  type = _ref$type === undefined ? "creation" : _ref$type,
67
88
  _ref$onFormSubmit = _ref.onFormSubmit,
@@ -70,25 +91,36 @@ function QurealViewer(_ref) {
70
91
  style = _ref$style === undefined ? {} : _ref$style;
71
92
 
72
93
 
73
- var sendToIFrame = function sendToIFrame(creation_slug) {
94
+ var sendToIFrame = function sendToIFrame(msg) {
74
95
  console.log("Sending data to iFrame");
75
96
  var qureal_element = document.getElementById("qureal_iframe");
76
97
 
77
98
  var qureal_window = qureal_element ? qureal_element.contentWindow : null;
78
99
  if (qureal_window) {
79
- qureal_window.postMessage({
80
- message_type: "OPEN_CREATION",
81
- data: {
82
- slug: creation_slug
83
- }
84
- }, "*");
100
+ qureal_window.postMessage(msg, "*");
85
101
  console.log("Data sent to iframe");
86
102
  }
87
103
  };
88
104
 
89
105
  React.useEffect(function () {
90
- sendToIFrame(slug);
91
- }, [slug]);
106
+ sendToIFrame({
107
+ message_type: "OPEN_CREATION",
108
+ data: {
109
+ slug: slug,
110
+ preview: preview,
111
+ prefill: prefill
112
+ }
113
+ });
114
+ }, [slug, preview]);
115
+
116
+ React.useEffect(function () {
117
+ sendToIFrame({
118
+ message_type: "PREFILL",
119
+ data: {
120
+ prefill: prefill
121
+ }
122
+ });
123
+ }, [prefill]);
92
124
 
93
125
  React.useEffect(function () {
94
126
  var handler = function handler(ev) {
@@ -112,10 +144,28 @@ function QurealViewer(_ref) {
112
144
 
113
145
  return React__default.createElement(QurealiFrame$1, {
114
146
  slug: slug,
147
+ preview: preview,
148
+ query: queryfy(prefill),
115
149
  type: type,
116
150
  style: style
117
151
  });
118
152
  }
119
153
 
154
+ function queryfy(obj) {
155
+ var buildQuery = function buildQuery(prefix, obj) {
156
+ return Object.keys(obj).map(function (key) {
157
+ var value = obj[key];
158
+ var prefixedKey = prefix ? prefix + "." + key : key;
159
+ if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === 'object' && value !== null) {
160
+ return buildQuery(prefixedKey, value);
161
+ } else {
162
+ return prefixedKey + "=" + value;
163
+ }
164
+ }).join("&");
165
+ };
166
+
167
+ return buildQuery("", obj);
168
+ }
169
+
120
170
  exports.QurealViewer = QurealViewer;
121
171
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}` : `https://show.qureal.com/ts/${slug}`}\n // src={`https://show.qureal.com/embed/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {}\n}) {\n\n const sendToIFrame = (creation_slug) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: creation_slug\n }\n }, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame(slug)\n }, [slug])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n"],"names":["QurealiFrame","slug","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","onFormSubmit","sendToIFrame","creation_slug","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","handler","ev","includes","origin","babelHelpers.typeof","data","event_type","addEventListener","window","removeEventListener"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAASA,YAAT,OAA+D;QAAvCC,IAAuC,QAAvCA,IAAuC;yBAAjCC,IAAiC;QAAjCA,IAAiC,6BAA1B,UAA0B;0BAAdC,KAAc;QAAdA,KAAc,8BAAN,EAAM;;;WAIvDC;sBAAA;;;gBAEW,eADP;mBAEU;;cAEN,KAAKF,SAAS,UAAT,sCAAuDD,IAAvD,mCAA8FA;;cAEnG;uBACW,MADX;wBAEY;eACLE,KAHP;;KARZ;;;;AAmBJ,qBAAeC,eAAMC,IAAN,CAAWL,YAAX,EAAyB;WAAM,IAAN;CAAzB,CAAf;;ACtBA,IAAMM,kBAAkB,CAAC,yBAAD,EAA4B,uBAA5B,CAAxB;;AAEA,SAASC,YAAT,OAKG;yBAJCN,IAID;QAJCA,IAID,6BAJQ,WAIR;yBAHCC,IAGD;QAHCA,IAGD,6BAHQ,UAGR;iCAFCM,YAED;QAFCA,YAED,qCAFgB,YAAM,EAEtB;0BADCL,KACD;QADCA,KACD,8BADS,EACT;;;QAEOM,eAAe,SAAfA,YAAe,CAACC,aAAD,EAAmB;gBAC5BC,GAAR,CAAY,wBAAZ;YACMC,iBAAiBC,SAASC,cAAT,CAAwB,eAAxB,CAAvB;;YAEMC,gBAAgBH,iBAAiBA,eAAeI,aAAhC,GAAgD,IAAtE;YACID,aAAJ,EAAmB;0BACDE,WAAd,CAA0B;8BACR,eADQ;sBAEhB;0BACIP;;aAHd,EAKG,GALH;oBAMQC,GAAR,CAAY,qBAAZ;;KAZR;;oBAgBU,YAAM;qBACCV,IAAb;KADJ,EAEG,CAACA,IAAD,CAFH;;oBAIU,YAAM;YACNiB,UAAU,SAAVA,OAAU,CAACC,EAAD,EAAQ;gBAChBb,gBAAgBc,QAAhB,CAAyBD,GAAGE,MAA5B,KAAuCC,QAAOH,GAAGI,IAAV,MAAmB,QAA9D,EAAwE;wBAC5DJ,GAAGI,IAAH,CAAQC,UAAhB;yBACS,aAAL;qCACiBL,GAAGI,IAAH,CAAQA,IAArB;;;gCAGQZ,GAAR,CAAY,qBAAZ;gCACQA,GAAR,CAAYQ,GAAGI,IAAf;;;SARhB;;eAaOE,gBAAP,CAAwB,SAAxB,EAAmCP,OAAnC;eACO;mBAAMQ,OAAOC,mBAAP,CAA2B,SAA3B,EAAsCT,OAAtC,CAAN;SAAP;KAfJ,EAgBG,EAhBH;;WAmBId,6BAACJ,cAAD;cACUC,IADV;cAEUC,IAFV;eAGWC;MAJf;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js"],"sourcesContent":["import React, { Fragment, useEffect, useRef } from \"react\";\n\n\nfunction QurealiFrame({ slug, preview, query, type = \"creation\", style = {} }) {\n\n\n return (\n <Fragment>\n <iframe\n id=\"qureal_iframe\"\n title=\"Qureal\"\n // src={`http://localhost:3201/embed/${creation_slug}`}\n src={type === \"creation\" ? `https://show.qureal.com/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n src={type === \"creation\" ? `http://localhost:3201/embed/${slug}?${preview ? \"preview&\" : \"\"}${query}` : `https://show.qureal.com/ts/${slug}`}\n style={{\n width: \"100%\",\n height: \"100vh\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\n\nconst ALLOWED_ORIGINS = [\"https://show.qureal.com\", \"http://localhost:3201\"];\n\nfunction QurealViewer({\n slug = \"qi_sample\",\n preview = false,\n prefill = {},\n type = \"creation\", // creation or template \n onFormSubmit = () => { },\n style = {}\n}) {\n\n const sendToIFrame = (msg) => {\n console.log(\"Sending data to iFrame\")\n const qureal_element = document.getElementById(\"qureal_iframe\");\n\n const qureal_window = qureal_element ? qureal_element.contentWindow : null;\n if (qureal_window) {\n qureal_window.postMessage(msg, \"*\");\n console.log(\"Data sent to iframe\")\n }\n }\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"OPEN_CREATION\",\n data: {\n slug: slug,\n preview: preview,\n prefill: prefill\n }\n })\n }, [slug, preview])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"PREFILL\",\n data: {\n prefill: prefill\n }\n })\n }, [prefill])\n\n useEffect(() => {\n const handler = (ev) => {\n if (ALLOWED_ORIGINS.includes(ev.origin) && typeof ev.data === \"object\") {\n switch (ev.data.event_type) {\n case \"FORM_SUBMIT\":\n onFormSubmit(ev.data.data);\n break;\n default:\n console.log(\"No event type found\");\n console.log(ev.data);\n }\n }\n };\n\n window.addEventListener(\"message\", handler);\n return () => window.removeEventListener(\"message\", handler);\n }, []);\n\n return (\n <QurealiFrame\n slug={slug}\n preview={preview}\n query={queryfy(prefill)}\n type={type}\n style={style}\n />\n );\n}\n\n// export default QurealiFrame;\nexport default QurealViewer\n\n\nfunction queryfy(obj) {\n const buildQuery = (prefix, obj) => {\n return Object.keys(obj)\n .map(key => {\n const value = obj[key];\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n if (typeof value === 'object' && value !== null) {\n return buildQuery(prefixedKey, value);\n } else {\n return `${prefixedKey}=${value}`;\n }\n })\n .join(\"&\");\n };\n\n return buildQuery(\"\", obj);\n}"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","handler","ev","includes","origin","babelHelpers.typeof","data","event_type","addEventListener","window","removeEventListener","queryfy","obj","buildQuery","prefix","Object","keys","map","value","key","prefixedKey","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAASA,YAAT,OAA+E;;;QAAvDC,IAAuD,QAAvDA,IAAuD;Q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"1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Official Qureal React components",
5
5
  "author": "shivampip",
6
6
  "license": "MIT",