qureal-editor 1.0.17 → 1.0.18
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 +79 -0
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -6,6 +6,35 @@ 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 asyncToGenerator = function (fn) {
|
|
10
|
+
return function () {
|
|
11
|
+
var gen = fn.apply(this, arguments);
|
|
12
|
+
return new Promise(function (resolve, reject) {
|
|
13
|
+
function step(key, arg) {
|
|
14
|
+
try {
|
|
15
|
+
var info = gen[key](arg);
|
|
16
|
+
var value = info.value;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
reject(error);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (info.done) {
|
|
23
|
+
resolve(value);
|
|
24
|
+
} else {
|
|
25
|
+
return Promise.resolve(value).then(function (value) {
|
|
26
|
+
step("next", value);
|
|
27
|
+
}, function (err) {
|
|
28
|
+
step("throw", err);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return step("next");
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
9
38
|
var _extends = Object.assign || function (target) {
|
|
10
39
|
for (var i = 1; i < arguments.length; i++) {
|
|
11
40
|
var source = arguments[i];
|
|
@@ -93,6 +122,53 @@ var QurealiFrame$1 = React.memo(QurealiFrame, function () {
|
|
|
93
122
|
return true;
|
|
94
123
|
});
|
|
95
124
|
|
|
125
|
+
var share = function () {
|
|
126
|
+
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
|
|
127
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
128
|
+
while (1) {
|
|
129
|
+
switch (_context.prev = _context.next) {
|
|
130
|
+
case 0:
|
|
131
|
+
_context.prev = 0;
|
|
132
|
+
|
|
133
|
+
if (!(navigator.share && navigator.canShare(data))) {
|
|
134
|
+
_context.next = 6;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_context.next = 4;
|
|
139
|
+
return navigator.share(data);
|
|
140
|
+
|
|
141
|
+
case 4:
|
|
142
|
+
_context.next = 8;
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case 6:
|
|
146
|
+
console.error("Can't share");
|
|
147
|
+
alert("Share only available for mobile devices");
|
|
148
|
+
|
|
149
|
+
case 8:
|
|
150
|
+
_context.next = 13;
|
|
151
|
+
break;
|
|
152
|
+
|
|
153
|
+
case 10:
|
|
154
|
+
_context.prev = 10;
|
|
155
|
+
_context.t0 = _context["catch"](0);
|
|
156
|
+
|
|
157
|
+
console.error(_context.t0);
|
|
158
|
+
|
|
159
|
+
case 13:
|
|
160
|
+
case "end":
|
|
161
|
+
return _context.stop();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}, _callee, this, [[0, 10]]);
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
return function share(_x) {
|
|
168
|
+
return _ref.apply(this, arguments);
|
|
169
|
+
};
|
|
170
|
+
}();
|
|
171
|
+
|
|
96
172
|
var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
|
|
97
173
|
|
|
98
174
|
function QurealViewer(_ref) {
|
|
@@ -177,6 +253,9 @@ function QurealViewer(_ref) {
|
|
|
177
253
|
case "FORM_SUBMIT":
|
|
178
254
|
onFormSubmit(ev.data.data);
|
|
179
255
|
break;
|
|
256
|
+
case "SHARE":
|
|
257
|
+
share(ev.data.data);
|
|
258
|
+
break;
|
|
180
259
|
default:
|
|
181
260
|
console.log("No event type found");
|
|
182
261
|
console.log(ev.data);
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js","../src/use-action.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}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\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 outline: \"none\",\n border: \"1px solid #777\",\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 actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\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 if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\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)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\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}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/QurealiFrame.js","../src/utils.js","../src/QurealViewer.js","../src/use-action.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}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\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 outline: \"none\",\n border: \"1px solid #777\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","export async function share(data) {\n try {\n if (navigator.share && navigator.canShare(data)) {\n await navigator.share(data);\n } else {\n console.error(\"Can't share\");\n alert(\"Share only available for mobile devices\")\n }\n } catch (err) {\n console.error(err);\n }\n}","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\nimport { share } from \"./utils\";\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 actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\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 if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\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 case \"SHARE\":\n share(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)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\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}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","data","navigator","share","canShare","error","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","handler","ev","origin","babelHelpers.typeof","event_type","addEventListener","window","removeEventListener","queryfy","obj","buildQuery","prefix","Object","keys","map","value","key","prefixedKey","join","useQurealActions","useState","setActionRef","download"],"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;;;cAGN,mCAAgCD,SAAS,UAAT,GAAsB,OAAtB,GAAgC,IAAhE,UAAwEH,IAAxE,UAAgFC,UAAU,UAAV,GAAuB,EAAvG,IAA4GC;;cAE5G;uBACW,MADX;wBAEY,OAFZ;yBAGa,MAHb;wBAIY;eACLE,KALP;;KATZ;;;;AAsBJ,qBAAeC,MAAMC,IAAN,CAAWP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,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;;;ACvHJ,SAASU,gBAAT,GAA4B;oBACUC,SAAS,EAAT,CADV;;QACjBnC,SADiB;QACNoC,YADM;;aAGfC,QAAT,GAAoB;qBACH;kBACH,UADG;kBAEH;SAFV;;;aAOK5C,KAAT,GAAiB;qBACA;kBACH,OADG;kBAEH;SAFV;;;WAMG,EAAEO,oBAAF,EAAaqC,kBAAb,EAAuB5C,YAAvB,EAAP;;;;;"}
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,35 @@ 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 asyncToGenerator = function (fn) {
|
|
17
|
+
return function () {
|
|
18
|
+
var gen = fn.apply(this, arguments);
|
|
19
|
+
return new Promise(function (resolve, reject) {
|
|
20
|
+
function step(key, arg) {
|
|
21
|
+
try {
|
|
22
|
+
var info = gen[key](arg);
|
|
23
|
+
var value = info.value;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
reject(error);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (info.done) {
|
|
30
|
+
resolve(value);
|
|
31
|
+
} else {
|
|
32
|
+
return Promise.resolve(value).then(function (value) {
|
|
33
|
+
step("next", value);
|
|
34
|
+
}, function (err) {
|
|
35
|
+
step("throw", err);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return step("next");
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
16
45
|
var _extends = Object.assign || function (target) {
|
|
17
46
|
for (var i = 1; i < arguments.length; i++) {
|
|
18
47
|
var source = arguments[i];
|
|
@@ -100,6 +129,53 @@ var QurealiFrame$1 = React__default.memo(QurealiFrame, function () {
|
|
|
100
129
|
return true;
|
|
101
130
|
});
|
|
102
131
|
|
|
132
|
+
var share = function () {
|
|
133
|
+
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(data) {
|
|
134
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
135
|
+
while (1) {
|
|
136
|
+
switch (_context.prev = _context.next) {
|
|
137
|
+
case 0:
|
|
138
|
+
_context.prev = 0;
|
|
139
|
+
|
|
140
|
+
if (!(navigator.share && navigator.canShare(data))) {
|
|
141
|
+
_context.next = 6;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
_context.next = 4;
|
|
146
|
+
return navigator.share(data);
|
|
147
|
+
|
|
148
|
+
case 4:
|
|
149
|
+
_context.next = 8;
|
|
150
|
+
break;
|
|
151
|
+
|
|
152
|
+
case 6:
|
|
153
|
+
console.error("Can't share");
|
|
154
|
+
alert("Share only available for mobile devices");
|
|
155
|
+
|
|
156
|
+
case 8:
|
|
157
|
+
_context.next = 13;
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
case 10:
|
|
161
|
+
_context.prev = 10;
|
|
162
|
+
_context.t0 = _context["catch"](0);
|
|
163
|
+
|
|
164
|
+
console.error(_context.t0);
|
|
165
|
+
|
|
166
|
+
case 13:
|
|
167
|
+
case "end":
|
|
168
|
+
return _context.stop();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}, _callee, this, [[0, 10]]);
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
return function share(_x) {
|
|
175
|
+
return _ref.apply(this, arguments);
|
|
176
|
+
};
|
|
177
|
+
}();
|
|
178
|
+
|
|
103
179
|
var ALLOWED_ORIGINS = ["https://show.qureal.com", "http://localhost:3201"];
|
|
104
180
|
|
|
105
181
|
function QurealViewer(_ref) {
|
|
@@ -184,6 +260,9 @@ function QurealViewer(_ref) {
|
|
|
184
260
|
case "FORM_SUBMIT":
|
|
185
261
|
onFormSubmit(ev.data.data);
|
|
186
262
|
break;
|
|
263
|
+
case "SHARE":
|
|
264
|
+
share(ev.data.data);
|
|
265
|
+
break;
|
|
187
266
|
default:
|
|
188
267
|
console.log("No event type found");
|
|
189
268
|
console.log(ev.data);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/QurealiFrame.js","../src/QurealViewer.js","../src/use-action.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}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\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 outline: \"none\",\n border: \"1px solid #777\",\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 actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\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 if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\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)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\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}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/QurealiFrame.js","../src/utils.js","../src/QurealViewer.js","../src/use-action.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}?${preview ? \"preview&\" : \"\"}${query}`}\n src={`https://show.qureal.com/${type === \"creation\" ? \"embed\" : \"ts\"}/${slug}?${preview ? \"preview&\" : \"\"}${query}`}\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 outline: \"none\",\n border: \"1px solid #777\",\n ...style\n }}\n />\n </Fragment>\n );\n}\n\n// export default QurealiFrame;\nexport default React.memo(QurealiFrame, () => true)\n","export async function share(data) {\n try {\n if (navigator.share && navigator.canShare(data)) {\n await navigator.share(data);\n } else {\n console.error(\"Can't share\");\n alert(\"Share only available for mobile devices\")\n }\n } catch (err) {\n console.error(err);\n }\n}","import React, { Fragment, useEffect, useRef } from \"react\";\nimport QurealiFrame from \"./QurealiFrame\";\nimport { share } from \"./utils\";\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 actionRef = {},\n organization = null,\n person = null,\n background = null,\n fit = false,\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 if ([\"DOWNLOAD\", \"SHARE\"].includes(actionRef.type)) {\n sendToIFrame({\n message_type: actionRef.type,\n data: actionRef.data || {}\n })\n }\n }, [actionRef])\n\n useEffect(() => {\n sendToIFrame({\n message_type: \"SET_ICTX\",\n data: {\n organization: organization,\n person: person\n }\n })\n }, [organization, person])\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 case \"SHARE\":\n share(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)}${organization ? `&qi_organization=${organization}` : \"\"}${person ? `&qi_person=${person}` : \"\"}${background ? `&qi_background=${background}` : \"\"}${fit ? \"&qi_fit\" : \"\"}`}\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}","import { useState } from \"react\"\n\nfunction useQurealActions() {\n const [actionRef, setActionRef] = useState({});\n\n function download() {\n setActionRef({\n type: \"DOWNLOAD\",\n data: {}\n })\n }\n\n\n function share() {\n setActionRef({\n type: \"SHARE\",\n data: {}\n })\n }\n\n return { actionRef, download, share }\n}\n\nexport default useQurealActions;"],"names":["QurealiFrame","slug","preview","query","type","style","React","memo","data","navigator","share","canShare","error","ALLOWED_ORIGINS","QurealViewer","prefill","onFormSubmit","actionRef","organization","person","background","fit","sendToIFrame","msg","log","qureal_element","document","getElementById","qureal_window","contentWindow","postMessage","includes","handler","ev","origin","babelHelpers.typeof","event_type","addEventListener","window","removeEventListener","queryfy","obj","buildQuery","prefix","Object","keys","map","value","key","prefixedKey","join","useQurealActions","useState","setActionRef","download"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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