qureal-editor 1.0.8 → 1.0.10

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
@@ -22,6 +22,8 @@ var _extends = Object.assign || function (target) {
22
22
 
23
23
  function QurealiFrame(_ref) {
24
24
  var slug = _ref.slug,
25
+ preview = _ref.preview,
26
+ query = _ref.query,
25
27
  _ref$type = _ref.type,
26
28
  type = _ref$type === undefined ? "creation" : _ref$type,
27
29
  _ref$style = _ref.style,
@@ -35,8 +37,8 @@ function QurealiFrame(_ref) {
35
37
  id: "qureal_iframe",
36
38
  title: "Qureal"
37
39
  // 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
+ , src: type === "creation" ? "https://show.qureal.com/embed/" + slug + "?" + (preview ? "preview&" : "") + query : "https://show.qureal.com/ts/" + slug
41
+ // src={type === "creation" ? `http://localhost:3201/embed/${slug}?${preview ? "preview&" : ""}${query}` : `https://show.qureal.com/ts/${slug}`}
40
42
  , style: _extends({
41
43
  width: "100%",
42
44
  height: "100vh"
@@ -55,6 +57,10 @@ var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
55
57
  function QurealViewer(_ref) {
56
58
  var _ref$slug = _ref.slug,
57
59
  slug = _ref$slug === undefined ? "qi_sample" : _ref$slug,
60
+ _ref$preview = _ref.preview,
61
+ preview = _ref$preview === undefined ? false : _ref$preview,
62
+ _ref$prefill = _ref.prefill,
63
+ prefill = _ref$prefill === undefined ? {} : _ref$prefill,
58
64
  _ref$type = _ref.type,
59
65
  type = _ref$type === undefined ? "creation" : _ref$type,
60
66
  _ref$onFormSubmit = _ref.onFormSubmit,
@@ -63,25 +69,36 @@ function QurealViewer(_ref) {
63
69
  style = _ref$style === undefined ? {} : _ref$style;
64
70
 
65
71
 
66
- var sendToIFrame = function sendToIFrame(creation_slug) {
72
+ var sendToIFrame = function sendToIFrame(msg) {
67
73
  console.log("Sending data to iFrame");
68
74
  var qureal_element = document.getElementById("qureal_iframe");
69
75
 
70
76
  var qureal_window = qureal_element ? qureal_element.contentWindow : null;
71
77
  if (qureal_window) {
72
- qureal_window.postMessage({
73
- message_type: "OPEN_CREATION",
74
- data: {
75
- slug: creation_slug
76
- }
77
- }, "*");
78
+ qureal_window.postMessage(msg, "*");
78
79
  console.log("Data sent to iframe");
79
80
  }
80
81
  };
81
82
 
82
83
  useEffect(function () {
83
- sendToIFrame(slug);
84
- }, [slug]);
84
+ sendToIFrame({
85
+ message_type: "OPEN_CREATION",
86
+ data: {
87
+ slug: slug,
88
+ preview: preview,
89
+ prefill: prefill
90
+ }
91
+ });
92
+ }, [slug, preview]);
93
+
94
+ useEffect(function () {
95
+ sendToIFrame({
96
+ message_type: "PREFILL",
97
+ data: {
98
+ prefill: prefill
99
+ }
100
+ });
101
+ }, [prefill]);
85
102
 
86
103
  useEffect(function () {
87
104
  var handler = function handler(ev) {
@@ -105,10 +122,28 @@ function QurealViewer(_ref) {
105
122
 
106
123
  return React.createElement(QurealiFrame$1, {
107
124
  slug: slug,
125
+ preview: preview,
126
+ query: queryfy(prefill),
108
127
  type: type,
109
128
  style: style
110
129
  });
111
130
  }
112
131
 
132
+ function queryfy(obj) {
133
+ var buildQuery = function buildQuery(prefix, obj) {
134
+ return Object.keys(obj).map(function (key) {
135
+ var value = obj[key];
136
+ var prefixedKey = prefix ? prefix + "." + key : key;
137
+ if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === 'object' && value !== null) {
138
+ return buildQuery(prefixedKey, value);
139
+ } else {
140
+ return prefixedKey + "=" + value;
141
+ }
142
+ }).join("&");
143
+ };
144
+
145
+ return buildQuery("", obj);
146
+ }
147
+
113
148
  export { QurealViewer };
114
149
  //# 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,QAA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D,CAPH;;cASU,YAAM;YACNW,UAAU,SAAVA,OAAU,CAACC,EAAD,EAAQ;gBAChBd,gBAAgBe,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,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
@@ -29,6 +29,8 @@ var _extends = Object.assign || function (target) {
29
29
 
30
30
  function QurealiFrame(_ref) {
31
31
  var slug = _ref.slug,
32
+ preview = _ref.preview,
33
+ query = _ref.query,
32
34
  _ref$type = _ref.type,
33
35
  type = _ref$type === undefined ? "creation" : _ref$type,
34
36
  _ref$style = _ref.style,
@@ -42,8 +44,8 @@ function QurealiFrame(_ref) {
42
44
  id: "qureal_iframe",
43
45
  title: "Qureal"
44
46
  // 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
+ , src: type === "creation" ? "https://show.qureal.com/embed/" + slug + "?" + (preview ? "preview&" : "") + query : "https://show.qureal.com/ts/" + slug
48
+ // src={type === "creation" ? `http://localhost:3201/embed/${slug}?${preview ? "preview&" : ""}${query}` : `https://show.qureal.com/ts/${slug}`}
47
49
  , style: _extends({
48
50
  width: "100%",
49
51
  height: "100vh"
@@ -62,6 +64,10 @@ var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
62
64
  function QurealViewer(_ref) {
63
65
  var _ref$slug = _ref.slug,
64
66
  slug = _ref$slug === undefined ? "qi_sample" : _ref$slug,
67
+ _ref$preview = _ref.preview,
68
+ preview = _ref$preview === undefined ? false : _ref$preview,
69
+ _ref$prefill = _ref.prefill,
70
+ prefill = _ref$prefill === undefined ? {} : _ref$prefill,
65
71
  _ref$type = _ref.type,
66
72
  type = _ref$type === undefined ? "creation" : _ref$type,
67
73
  _ref$onFormSubmit = _ref.onFormSubmit,
@@ -70,25 +76,36 @@ function QurealViewer(_ref) {
70
76
  style = _ref$style === undefined ? {} : _ref$style;
71
77
 
72
78
 
73
- var sendToIFrame = function sendToIFrame(creation_slug) {
79
+ var sendToIFrame = function sendToIFrame(msg) {
74
80
  console.log("Sending data to iFrame");
75
81
  var qureal_element = document.getElementById("qureal_iframe");
76
82
 
77
83
  var qureal_window = qureal_element ? qureal_element.contentWindow : null;
78
84
  if (qureal_window) {
79
- qureal_window.postMessage({
80
- message_type: "OPEN_CREATION",
81
- data: {
82
- slug: creation_slug
83
- }
84
- }, "*");
85
+ qureal_window.postMessage(msg, "*");
85
86
  console.log("Data sent to iframe");
86
87
  }
87
88
  };
88
89
 
89
90
  React.useEffect(function () {
90
- sendToIFrame(slug);
91
- }, [slug]);
91
+ sendToIFrame({
92
+ message_type: "OPEN_CREATION",
93
+ data: {
94
+ slug: slug,
95
+ preview: preview,
96
+ prefill: prefill
97
+ }
98
+ });
99
+ }, [slug, preview]);
100
+
101
+ React.useEffect(function () {
102
+ sendToIFrame({
103
+ message_type: "PREFILL",
104
+ data: {
105
+ prefill: prefill
106
+ }
107
+ });
108
+ }, [prefill]);
92
109
 
93
110
  React.useEffect(function () {
94
111
  var handler = function handler(ev) {
@@ -112,10 +129,28 @@ function QurealViewer(_ref) {
112
129
 
113
130
  return React__default.createElement(QurealiFrame$1, {
114
131
  slug: slug,
132
+ preview: preview,
133
+ query: queryfy(prefill),
115
134
  type: type,
116
135
  style: style
117
136
  });
118
137
  }
119
138
 
139
+ function queryfy(obj) {
140
+ var buildQuery = function buildQuery(prefix, obj) {
141
+ return Object.keys(obj).map(function (key) {
142
+ var value = obj[key];
143
+ var prefixedKey = prefix ? prefix + "." + key : key;
144
+ if ((typeof value === "undefined" ? "undefined" : _typeof(value)) === 'object' && value !== null) {
145
+ return buildQuery(prefixedKey, value);
146
+ } else {
147
+ return prefixedKey + "=" + value;
148
+ }
149
+ }).join("&");
150
+ };
151
+
152
+ return buildQuery("", obj);
153
+ }
154
+
120
155
  exports.QurealViewer = QurealViewer;
121
156
  //# 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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,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;QAAjDC,OAAiD,QAAjDA,OAAiD;QAAxCC,KAAwC,QAAxCA,KAAwC;yBAAjCC,IAAiC;QAAjCA,IAAiC,6BAA1B,UAA0B;0BAAdC,KAAc;QAAdA,KAAc,8BAAN,EAAM;;;WAIvEC;sBAAA;;;gBAEW,eADP;mBAEU;;cAEN,KAAK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AL;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;;WAmBIf,6BAACN,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qureal-editor",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Official Qureal React components",
5
5
  "author": "shivampip",
6
6
  "license": "MIT",